Q:

Write a NumPy program to create an element-wise comparison (equal, equal within a tolerance) of two given arrays

0

Write a NumPy program to create an element-wise comparison (equal, equal within a tolerance) of two given arrays

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

import numpy as np
x = np.array([72, 79, 85, 90, 150, -135, 120, -10, 60, 100])
y = np.array([72, 79, 85, 90, 150, -135, 120, -10, 60, 100.000001])
print("Original numbers:")
print(x)
print(y)
print("Comparison - equal:")
print(np.equal(x, y))
print("Comparison - equal within a tolerance:")
print(np.allclose(x, y))

Sample Output:

Original numbers:
[  72   79   85   90  150 -135  120  -10   60  100]
[  72.         79.         85.         90.        150.       -135.
  120.        -10.         60.        100.000001]
Comparison - equal:
[ True  True  True  True  True  True  True  True  True False]
Comparison - equal within a tolerance:
True

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now