Home > front end >  How to mask indices smaller than or bigger than certain index?
How to mask indices smaller than or bigger than certain index?

Time:11-01

Is there a way to mask, using np.ma module, all indices in a specific array smaller or bigger than a given number? For example, if I have an array of 365 elements and I want to mask all of the ones between 170 and 200 and only take into account[0:170] and [201:], can I do it?

Tried researching the answer but nothing I found seems like the right solution (it's not an issue for me to mask the indices using for example list comprehension, but I specifically need to use the np.ma module)

CodePudding user response:

You could make a mask along the lines of

mymask = np.array([0 if x < 170 or x >=200 else 1 for x in range(365)])

and then use

x = np.ma.masked_array(myarray, mask = mymask)
  • Related