I have a list of boolean arrays constructed using the numpy where function, e.g.:
A[0] = [False, False, True, True, True, False, False,False,False,False]
A[1] = [False, False, False, False,False,False, True, True, True,False]
A[2] = [False,True, True, True, False, False, False, False,False,False]
...
A few notes:
- the real arrays have something like 10 000 elements
- there are several "true" windows on each array
- the "true" windows might overlap from array to array
- all arrays have the same length L
I need to:
1) combine all arrays into one single array with length L that will contain all "True" values
2) recover for each "True" window the inicial and final index
any ideas?
Thanks!
EDIT
The expected result is: R = [False,True, True, True, True, False, True, True, True, False]
In terms of code:
import numpy as np
data = np.arange(1,100)
list_of_lists = [[5,10], [15,25], [45,85]]
A = [np.where((data < list[1]) & (data > list[0]))[0] for list in list_of_lists]
Output:
>>> print A
[array([5, 6, 7, 8]), array([15, 16, 17, 18, 19, 20, 21, 22, 23]), array([45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61,
62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78,
79, 80, 81, 82, 83])]
the desired result:
R = [[5,8],[15,23],[45,83]]
True or False
-->True
. – wwii