Python NumPy Arrays Comparison
kodingwindow@kw:~$ python3 ... >>> from numpy import * >>> arr1 = array([1, 0, -1, 3.14, "Kodingwindow"]) >>> arr2 = array([0, 0, -1, 3.14, 'K', 'W']) >>> arr1.size, arr2.size (5, 6) >>> arr1 == arr2<stdin>:1: FutureWarning: elementwise comparison failed; returning scalar instead, but in the future will perform elementwise comparison False >>> arr2 = array([0, 0, -1, 3.14, 'K']) >>> arr1.size, arr2.size (5, 5) >>> arr1 == arr2 array([False, True, True, True, False])
>>> arr1 = array([1, 2, 3, 4, 5]) >>> arr2 = array([5, 4, 3, 2, 1]) >>> arr1 == arr2 array([False, False, True, False, False]) >>> arr1 != arr2 array([ True, True, False, True, True]) >>> arr1 >= arr2 array([False, False, True, True, True]) >>> arr1 <= arr2 array([ True, True, True, False, False]) >>> any(arr1 > 2) True >>> any(arr1 > 5) False >>> all(arr1 > 0) True >>> all(arr1 > 1) False >>> logical_and(arr1 >= 3, arr1 <= 3) array([False, False, True, False, False]) >>> logical_or(arr1 >= 3, arr1 <= 3) array([ True, True, True, True, True])
What Next?
Python NumPy Mathematical Functions for Arrays
Python indexing and slicing on NumPy arrays
How to create arrays using the linspace() and logspace() functions
Advertisement