You can subset a numpy array by indexing with a boolean condition. Here's an example of how to subset a numpy array arr
by a condition:
main.py136 chars10 lines
In this example, subset_arr
will contain only the elements of arr
that are greater than 3.
You can also use logical operators to chain conditions together when subsetting:
main.py40 chars2 lines
This will subset arr
to only contain elements that are greater than 2 and less than 5.
gistlibby LogSnag