Q:

Write a NumPy program to check whether two arrays are equal (element wise) or not

0

Write a NumPy program to check whether two arrays are equal (element wise) or not

All Answers

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

import numpy as np
nums1 = np.array([0.5, 1.5, 0.2])
nums2 = np.array([0.4999999999, 1.500000000, 0.2])
np.set_printoptions(precision=15)
print("Original arrays:")
print(nums1)
print(nums2)
print("\nTest said two arrays are equal (element wise) or not:?")
print(nums1 == nums2)
nums1 = np.array([0.5, 1.5, 0.23])
nums2 = np.array([0.4999999999, 1.5000000001, 0.23])
print("\nOriginal arrays:")
np.set_printoptions(precision=15)
print(nums1)
print(nums2)
print("\nTest said two arrays are equal (element wise) or not:?")
print(np.equal(nums1, nums2))

Sample Output:

Original arrays:
[0.5 1.5 0.2]
[0.4999999999 1.5          0.2         ]

Test said two arrays are equal (element wise) or not:?
[False  True  True]

Original arrays:
[0.5  1.5  0.23]
[0.4999999999 1.5000000001 0.23        ]

Test said two arrays are equal (element wise) or not:?
[False False  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