Any of those help I'm very new in Python and in Numpy. In fact, I'm just learning. , You have 3 arrays in 1 array: [
[ 0, 1, 2, 3, 4],
[ 5, 6, 7, 8, 9],
[10, 11, 12, 13, 14]
]
[
[15, 16, 17, 18, 19],
[20, 21, 22, 23, 24],
[25, 26, 27, 28, 29]
]
Boards Message : 
You Must Login
Or Sign Up
to Add Your Comments . 
Share :

Indexing a Boolean Array with another Boolean Array in Python
Date : March 29 2020, 07:55 AM
I wish this helpful for you I have a dataset with two Boolean arrays. , Here you go. That does exactly what you need. errors_with_length = [b for b, l in zip(Boolean_error, Has_length) if l]
>>> list(itertools.compress(Boolean_error, Has_length))
[False, True, False, True, False, True, False, False, False, False]

weird result when using both slice indexing and boolean indexing on a 3d array
Date : March 29 2020, 07:55 AM
will help you a[0, :, mask] mixes advanced indexing with slicing. The : is a "slice index", while the 0 (for this purpose) and mask are consider "advanced indexes". The rules governing the behavior of indexing when both advanced indexing and slicing are combined state:

Numpy  Indexing with Boolean array
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further I have a numpy array of shape (6,5) and i am trying to index it with Boolean arrays. I slice the boolean array along the columns and then use that slice to index the original array, everything is fine, however as soon as i do the same thing along the rows i get the below error. Below is my code, , Since there are only 5 entries in rows, In [18]: rows
Out[18]: array([ True, True, False, False, False], dtype=bool)
In [20]: arr.shape
Out[20]: (6, 5)
In [21]: rows.shape
Out[21]: (5,)
# select all rows but only columns where rows is `True`
In [19]: arr[:, rows]
Out[19]:
array([[73, 20],
[18, 66],
[27, 83],
[78, 74],
[26, 18],
[41, 16]])

Boolean indexing array through array of boolean indexes without loop
Date : March 29 2020, 07:55 AM
will help you Approach #1 Simply broadcast a to b's shape with np.broadcast_to and then mask it with b  In [15]: np.broadcast_to(a,b.shape)[b]
Out[15]: array([0, 2, 2, 3])
a.ravel()[np.flatnonzero(b)%a.size]
_,r,c = np.nonzero(b)
out = a[r,c]
In [50]: np.random.seed(0)
...: a = np.random.rand(200,200)
...: b = np.random.rand(200,200,200)>0.5
In [51]: %timeit np.broadcast_to(a,b.shape)[b]
45.5 ms ± 381 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)
In [52]: %timeit a.ravel()[np.flatnonzero(b)%a.size]
94.6 ms ± 1.64 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)
In [53]: %%timeit
...: _,r,c = np.nonzero(b)
...: out = a[r,c]
128 ms ± 1.46 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)

Trying to understand boolean array indexing
Date : March 29 2020, 07:55 AM

