I want to stack arrays with this code.
a = np.array([[1, 2, 3], [4, 5, 6]])
b = np.array([7, 8])
np.stack((a, b), axis=-1)
But it returns
ValueError: all input arrays must have the same shape error.
I expect the output to be:
array([[[1, 2, 3], 7],
[[4, 5, 6], 8]])
np.objectas a result, or are you looking forarray([[[1, 2, 3, 7], [[4, 5, 6, 8]])?ais a (n,3) numeric array; in the combined array, it is broken up inton(3,) arrays. To recoverayou'd have to usenp.stack(res[:,0]). The combined array will use more memory, and for most operations will be harder to use.