Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Vector of zeros and ones given a condition

Let x be a numeric vector. In Matlab typing:

y=1*(x>0.1)

Gives a vector of the same size as x with ones and zeros depending on whether the corresponding element in x satisfies the condition. Is there a similar short hand statement in Python (or common library) to achieve this without a loop?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

y = [ int(z > 1) for  z in x] 
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading