I am starting with NumPy.
Given two np.arrays, queu and new_path:
queu = [ [[0 0]
[0 1]]
]
new_path = [ [[0 0]
[1 0]
[2 0]]
]
My goal is to get the following queu:
queu = [ [[0 0]
[0 1]]
[[0 0]
[1 0]
[2 0]]
]
I've tried:
np.append(queu, new_path, 0)
and
np.vstack((queu, new_path))
But both are raising
all the input array dimensions except for the concatenation axis must match exactly
I didn't get the NumPy philosophy. What am I doing wrong?
You have defined 2 arrays, with shape (1,2,2) and (1,3,2). If you are puzzled about those shapes you need to reread some of the basic
numpyintroduction.hstack,vstackandappendall callconcatenate. With 3d arrays using them will just confuse matters.Joining on the 2nd axis, which is size 2 for one and 3 for the other, works, producing a (1,5,2) array. (This is equivalent to
hstack)Trying to join on axis 0 (vstack) produces your error:
The concatenation axis is 0, but dimensions of axis 1 differ. Hence the error.
Your target is not a valid numpy array. You could collect them together in a list:
Or an object dtype array - but that's more advanced
numpy.