0

I want to get the position in a masked array. Like this

wt[chl > 10] = 3
wt[(chl < 10) & (chl > 5)] = 2
wt[(chl < 5)] = 1
wt[(chl is masked )]=0

wt and chl is in the same shape. I want to give wt value according to the value and attribute(masked or not) of chl.

Does anyone know what I should do?

Thank you in advance.

2 Answers2

0

argwhere returns the indices where a value is non-zero, so if the shapes are equal,

wt[np.argwhere(chi)] = 0

should zero wt where chi is nonzero (and ~np.argwhere(chi) zeroes the indices where chi is zero).

AKX
  • 152,115
  • 15
  • 115
  • 172
0

You can access the mask attribute of chl directly and use it as an index:

wt[chl.mask] = 0
AbbeGijly
  • 1,191
  • 1
  • 4
  • 5