Reputation: 761
I have this array:
array([[[10],
[20],
[30]],
[[20],
[30],
[40]]])
And this array:
array([[[110],
[120],
[130]]])
Both are 3d array where the dimensions are (2,3,1) and (1,3,1) respectively. I am trying to append the second array to the end of the first array, maintaining its as a 2d array as it seems. So that I would get this
array([[[10],
[20],
[30]],
[[20],
[30],
[40]],
[[110],
[120],
[130]]])
What I'm doing is this:
X = np.append(X[:,:,:],a[0])
but all I'm getting back is 1d array : array([ 10, 20, 30, 20, 30, 40, 110, 120, 130])
. This isn't what I want, any idea how to go about it? Thank you for reading.
Upvotes: 0
Views: 442
Reputation: 12417
Another way would be using vstack
:
np.vstack((a, b))
[[[ 10]
[ 20]
[ 30]]
[[ 20]
[ 30]
[ 40]]
[[110]
[120]
[130]]]
Upvotes: 0
Reputation: 34086
Use np.concatenate
:
In [214]: a = np.array([[[10],
...: [20],
...: [30]],
...:
...: [[20],
...: [30],
...: [40]]])
In [215]: b = np.array([[[110],
...: [120],
...: [130]]])
In [216]: np.concatenate((a, b))
Out[216]:
array([[[ 10],
[ 20],
[ 30]],
[[ 20],
[ 30],
[ 40]],
[[110],
[120],
[130]]])
Upvotes: 1