Reputation: 1013
I have an numpy array of size NxD called X.
I have created a mask of size D represented by a numpy vector with 1 and 0 called ind_delete
I would like to delete all column of X corresponding to 1 in ind_delete.
I have tried:
X = np.delete(X,ind_delete,1)
but it obviously does not work. I have tried to find an easy way to to that on python but as it is trivial in matlab, it seems not as much here. Thanks for pointing out the best way to achieve it.
Upvotes: 2
Views: 75
Reputation: 20424
>>> x = np.array([[1, 2, 3],
... [4, 5, 6]])
>>> d = np.array([1, 0, 1])
>>> x[:, d==1]
array([[1, 3],
[4, 6]])
Upvotes: 2
Reputation: 505
You need to create a boolean array and you can select what you want:
X = X[ind_delete!=1]
Selects the positions for where the value is not 1.
Upvotes: 0