How to extract all columns but one from an array (or matrix) in python?

Since for the general case you are going to be returning a copy anyway, you may find yourself producing more readable code by using np.delete:

>>> a = np.arange(12).reshape(3, 4)
>>> np.delete(a, 2, axis=1)
array([[ 0,  1,  3],
       [ 4,  5,  7],
       [ 8,  9, 11]])

Leave a Comment

tech