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

Combining "True" values in multiple list into a single list, (index sensitve)

Let’s suppose I have two lists:

l1 = np.zeros(5,bool)
l2 = np.zeros (5,bool)

l1[3] = True 
l2[1] = True 

Output:

[False False False  True False]
[False  True False False False]

And based on these lists I want a single list which has indexes set to true based on the index of Trues (one or more) in a number of lists. All the lists have the same length and the target list must have the same length as well. What could be the pythonic way to do that so that I may get the desired list:

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

List 3: Desired Output:

[False True False  True False]

>Solution :

If what I understand is that you want to apply an or operator between vectors, this would be the way to develop it:

import numpy as np

l1 = np.zeros(5,bool)
l2 = np.zeros (5,bool)

l1[3] = True 
l2[1] = True 

l_full = np.logical_or(l1,l2)
l_full
# array([False,  True, False,  True, False])
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