How to find the difference between the sum of all even and odd elements of an array in the python – style
Completely the task is as follows:
Generate an array of integers ranging from 0 to 100 of a dimension of 10 by 20 (10 lines, 20 columns). Find the difference of the sum of all even and odd elements.
The array generated something like this:
import numpy as np a = np.random.random_integers(0, 100, 200).reshape(10,20)
diff = a[even].sum() - a[~even].sum()whereeven = (a & 1) == 0. - jfs