﻿ NumPy: Compare two given arrays - w3resource # NumPy: Compare two given arrays

## NumPy: Array Object Exercise-28 with Solution

Write a NumPy program compare two given arrays.

Pictorial Presentation: Sample Solution:

NumPy Code:

``````import numpy as np
a = np.array([1, 2])
b = np.array([4, 5])
print("Array a: ",a)
print("Array b: ",b)
print("a > b")
print(np.greater(a, b))
print("a >= b")
print(np.greater_equal(a, b))
print("a < b")
print(np.less(a, b))
print("a <= b")
print(np.less_equal(a, b))
```
```

Sample Output:

```Array a:  [1 2]
Array b:  [4 5]
a > b
[False False]
a >= b
[False False]
a < b
[ True  True]
a <= b
[ True  True]
```

Python Code Editor:

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

What is the difficulty level of this exercise?

Test your Python skills with w3resource's quiz

﻿

## Python: Tips of the Day

Python: While-else construct

```i = 5

while i > 1:
print("Whil-ing away!")
i -= 1
if i == 3:
break
else:
print("Finished up!")
```