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.],
[ 4., 5., 6., 7.],
[ 8., 9., 10., 11.],
[ 12., 13., 14., 15.],
[ 16., 17., 18., 19.]], dtype=float32)
I tried:
arr = np.arange(20, dtype=np.float32)
matrix = arr.reshape(5, 4)
new_arr = numpy.delete(matrix, matrix[:,0])
trimmed_matrix = new_arr.reshape(5, 3)
It looks a bit clunky. Am I doing it correctly? If yes, is there a cleaner way to remove the dimension without reshaping?
(5, 3)array? Then you want to delete a column (or in general, an 'entry' from a dimension). Removing a dimension would be changing to a(5,)or a(4,)array.arr[:,1:].np.deleteworks by index, not value. It is notlistremove.