I have 2 arrays:
arr1 = np.linspace(1, 10, 10)
arr2 = np.linspace(50, 100, 10)
Then I want to do:
arr1 * arr2 == arr2 * arr1
But I want to get a single True
as output and not an array of True
s.
How can I do it?
CodePudding user response:
You can check if two arrays are equal in all elements using np.array_equal
:
np.array_equal(arr1 * arr2, arr2 * arr1)
In this particular case, you can reduce an array of bools to a single value using np.all
:
(arr1 * arr2 == arr2 * arr1).all()
OR
np.all(arr1 * arr2 == arr2 * arr1)