Let's extract the even elements from an array. Perform the following steps to do so:
arange
function.a = np.arange(7)
condition = (a % 2) == 0
extract
function.print "Even numbers", np.extract(condition, a)
This gives us the even numbers, as required:
Even numbers [0 2 4 6]
nonzero
function.print "Non zero", np.nonzero(a)
This prints all the non-zero values of the array, as follows:
Non zero (array([1, 2, 3, 4, 5, 6]),)