I have a 64*64 array, and would like to mask certain columns. For one column I know I can do:
mask = np.tri(64,k=0,dtype=bool)
col = np.zeros((64,64),bool)
col[:,3] = True
col_mask = col np.transpose(col)
col_mask = np.tril(col_mask)
col_mask = col_mask[mask]
but how to extend this to multiple indices? I have tried doing col[:,1] & col[:,2] = True
but got
SyntaxError: cannot assign to operator
Also I might have up to 10 columns I would like to mask, so is there a less unwieldily approach? I have also looked at numpy.indices but I don't think this is what I need. Thank you!
CodePudding user response:
You can update multiple indices at the same time:
idx = [1,2,3,10,50]
col[:,idx] = True