﻿ NumPy: Create an element-wise comparison (greater, greater_equal, less and less_equal) of two given arrays - w3resource

# NumPy: Create an element-wise comparison (greater, greater_equal, less and less_equal) of two given arrays

## NumPy: Basic Exercise-10 with Solution

Write a NumPy program to create an element-wise comparison (greater, greater_equal, less and less_equal) of two given arrays.

Sample Solution :

Python Code :

``````import numpy as np
x = np.array([3, 5])
y = np.array([2, 5])
print("Original numbers:")
print(x)
print(y)
print("Comparison - greater")
print(np.greater(x, y))
print("Comparison - greater_equal")
print(np.greater_equal(x, y))
print("Comparison - less")
print(np.less(x, y))
print("Comparison - less_equal")
print(np.less_equal(x, y))
``````

Sample Output:

```Original numbers:
[3 5]
[2 5]
Comparison - greater
[ True False]
Comparison - greater_equal
[ True  True]
Comparison - less
[False False]
Comparison - less_equal
[False  True]
```

Python Code Editor:

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

What is the difficulty level of this exercise?

﻿

Inviting useful, relevant, well-written and unique guest posts