python - ndarray concatenate error -


i wish concatenate following arrays:

a=np.array([[1,2],[1],[2,3,4]])     b=np.array([[20,2]])     np.concatenate((a,b),axis=0) 

but following error:

valueerror                                traceback (most recent call last) <ipython-input-40-42253341965b> in <module>() ----> 1 np.concatenate((a,b),axis=0)  valueerror: input arrays must have same number of dimensions 

i expecting answer [[1,2],[1],[2,3,4],[20,2]]. if b=np.array([20,2]) instead concatenation works fine except answer: [[1,2],[1],[2,3,4],20,2]

check dtype, ndim , shape of a: you'll find numpy.object, 1 , (3,), respectively. because array a contains lists of different lengths, each list treated object, , a 1 dimensional array of objects. don't know aiming for, if want a have ndim of 2, you'll need make sure lists have same length.

of course, b has ndim of 2, since contains 1 (nested) lists, result in regular n-dimensional array.

the error message obvious: you're trying concatenate 2 arrays different dimensions: won't work.

to answer you're seeking, [[1,2],[1],[2,3,4],[20,2]], you'll need convert inner list of b object well: you're concatenating 2 1 dimensional arrays of objects.


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -