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


generates array based on specified range


changes shape of the array to the specified dimensions


first condition to use


second condition to use

condition1 & condition2

use both conditions in where method


returns filtered elements from array based on condition