I have three arrays I1,I2,I3
with shape (1,9,2)
. I am trying to append but there is an error. The new array should have shape (3,9,2)
import numpy as np
I1 = np.array([[[0, 2],
[2, 3],
[2, 5],
[3, 4],
[3, 6],
[4, 1],
[4, 7],
[5, 6],
[6, 7]]])
I2 = np.array([[[1, 1],
[2, 3],
[2, 5],
[3, 4],
[3, 6],
[4, 1],
[4, 7],
[5, 6],
[6, 7]]])
I3 = np.array([[[2, 2],
[2, 3],
[2, 5],
[3, 4],
[3, 6],
[4, 1],
[4, 7],
[5, 6],
[6, 7]]])
I=np.append(I1,I2,I3,axis=0)
The error is
in <module>
Iit=np.append(Iit1,Iit2,Iit3,axis=0)
File "<__array_function__ internals>", line 4, in append
TypeError: _append_dispatcher() got multiple values for argument 'axis'
CodePudding user response:
Use I=np.concatenate([I1,I2,I3],axis=0)
rather than append
. Append does what you'd expect from a list (and try not to use it in numpy, anyway, for memory allocation reasons!)`
CodePudding user response:
A different way from @Dominik is
I = np.stack((I1,I2,I3))
stack creates a new axis.