9951 explained code solutions for 126 technologies


python-numpyHow to use multiple conditions in where()


import numpy as np
array = np.arange(0, 100).reshape(10,10)

condition1 = array > 15
condition2 = array < 25

filtered = array[np.where(condition1 & condition2)]ctrl + c
import numpy as np

load Numpy module for Python

.arange(

generates array based on specified range

.reshape(

changes shape of the array to the specified dimensions

condition1

first condition to use

condition2

second condition to use

condition1 & condition2

use both conditions in where method

where(

returns filtered elements from array based on condition