PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, November 1, 2022

[FIXED] How to mask indices smaller than or bigger than certain index?

 November 01, 2022     indexing, indices, numpy, python     No comments   

Issue

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)


Solution

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)


Answered By - user19077881
Answer Checked By - David Goodson (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing