Well, I agree with the other answers when they say that hstack or concatenate do the job in this case. However, I would like to point out that even if it βfixesβ the problem, the problem does not fix properly.
The problem is that even if it looks like the second axis has a different length, in practice this is not true. If you try:
>>> myArray.shape (2,) >>> myArray.dtype dtype('O')
It shows you that your array is not a two-dimensional array with a variable size (as you think), it is just a 1D array of objects. In your case, the list elements, which are the first element of your array, are a 2-element list, and the second element of the array is a list of 1 element.
So, flatten and ravel will not work, because converting a 1D array to a 1D array results in exactly one 1D array. If you have an object numpy array, it will not care about what you have enclosed inside it, it will consider individual elements as unregistered elements and cannot decide how to combine them.
What you should consider if this is the behavior you want for your application. Plural arrays are especially efficient with fixed-size numerical matrices. If you play with arrays of objects, I don't understand why you want to use Numpy instead of regular python lists.
source share