9951 explained code solutions for 126 technologies


python-numpyHow to use where() to filter array


import numpy as np

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

filtered = array[np.where(array > 80)]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

where(

returns filtered elements from array based on condition

array > 80

sample condition (choose only elements which value is more than 80)