Imagine we have a 5x4 matrix. We need to remove only the first dimension. How can we do it with numpy?
array([[ 0., 1., 2., 3.],
The correct way to use delete
is to specify index and dimension, eg. remove the 1st (0) column (dimension 1):
In [215]: np.delete(np.arange(20).reshape(5,4),0,1)
Out[215]:
array([[ 1, 2, 3],
[ 5, 6, 7],
[ 9, 10, 11],
[13, 14, 15],
[17, 18, 19]])
other expressions that work:
np.arange(20).reshape(5,4)[:,1:]
np.arange(20).reshape(5,4)[:,[1,2,3]]
np.arange(20).reshape(5,4)[:,np.array([False,True,True,True])]