December 2017
Intermediate to advanced
386 pages
10h 42m
English
A Boolean array can be used to select a subset of the items in an array according to a given condition, as illustrated in the following code:
condition = x > 87y = x[condition]
In this code, we first create the array condition, which is a Boolean array that holds a True value only at the positions that are larger than 87 in the array x. Next, we use the y=x[condition] statement to fetch the elements of x for which the condition is True. The overall effect is to generate an array that contains only the elements in x that are larger than 87, as follows:
array([88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99])
Notice that, when using a Boolean array in this way, the output is always a one-dimensional.
Another common ...
Read now
Unlock full access