Write a NumPy program that compares two arrays.
Source Code:
import numpy as np
n1 = int(input("Enter size of first array:"))
n2 = int(input("Enter size of second array:"))
ary1 = np.array([],dtype=int)
ary2 = np.array([],dtype=int)
if n1==n2:
print("Enter {} elements for first array".format(n1))
ary1 = np.append(ary1,list(map(int,input().split()))[:n1])
print("Enter {} elements for second array".format(n2))
ary2 = np.append(ary2,list(map(int,input().split()))[:n2])
cmp = ary1==ary2
if cmp.all():
print("Both arrays are same.")
else:
print("Arrays are different.")
else:
print("Arrays are different in size.")
Sample Output1:n1 = int(input("Enter size of first array:"))
n2 = int(input("Enter size of second array:"))
ary1 = np.array([],dtype=int)
ary2 = np.array([],dtype=int)
if n1==n2:
print("Enter {} elements for first array".format(n1))
ary1 = np.append(ary1,list(map(int,input().split()))[:n1])
print("Enter {} elements for second array".format(n2))
ary2 = np.append(ary2,list(map(int,input().split()))[:n2])
cmp = ary1==ary2
if cmp.all():
print("Both arrays are same.")
else:
print("Arrays are different.")
else:
print("Arrays are different in size.")
Enter size of first array:4
Enter size of second array:4
Enter 4 elements for first array
2 3 4 5
Enter 4 elements for second array
2 3 4 5
Both arrays are same.
Sample Output2:Enter size of second array:4
Enter 4 elements for first array
2 3 4 5
Enter 4 elements for second array
2 3 4 5
Both arrays are same.
Enter size of first array:4
Enter size of second array:4
Enter 4 elements for first array
2 4 6 8
Enter 4 elements for second array
1 3 5 7
Arrays are different.
Enter size of second array:4
Enter 4 elements for first array
2 4 6 8
Enter 4 elements for second array
1 3 5 7
Arrays are different.