Suppose I have the following numpy array:
a = [[1, 5, 6],
[2, 4, 1],
[3, 1, 5]]
I want to mask all the rows which have 1
in the first column. That is, I want
[[--, --, --],
[2, 4, 1],
[3, 1, 5]]
Is this possible to do using numpy masked array operations? How can one do it?
Thanks.
import numpy as np
a = np.array([[1, 5, 6],
[2, 4, 1],
[3, 1, 5]])
np.ma.MaskedArray(a, mask=(np.ones_like(a)*(a[:,0]==1)).T)
# Returns:
masked_array(data =
[[-- -- --]
[2 4 1]
[3 1 5]],
mask =
[[ True True True]
[False False False]
[False False False]])