Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Merge two numpy array's of different shape into a single array

I have two numpy array's a and b of length 53 and 82 respectively. I would like to merge them into a single array because I want to use the 53+82=135 length array say call it c for plotting.

I tried

c = a+b 

but I am getting ValueError: shape mismatch: objects cannot be broadcast to a single shape

Is this possible?

like image 688
Srivatsan Avatar asked Jan 11 '23 09:01

Srivatsan


1 Answers

You need to use numpy.concatenate instead of array addition

c = numpy.concatenate((a, b))

Implementation

import numpy as np
a = np.arange(53)
b = np.arange(82)
c = np.concatenate((a, b))

Output

c.shape
(135, )
like image 194
Abhijit Avatar answered Jan 19 '23 00:01

Abhijit