w3resource logo

:

Python Exercises

Python: Check two random arrays are equal or not

Python NumPy: Random Exercise-10 with Solution

Write a Python program to check two random arrays are equal or not.

Sample Solution :-

Python Code :

import numpy as np
x = np.random.randint(0,2,6)
print("First array:")
print(x)
y = np.random.randint(0,2,6)
print("Second array:")
print(y)
print("Test above two arrays are equal or not!")
array_equal = np.allclose(x, y)
print(array_equal)

Sample Output:

First array:                                                           
[1 0 0 0 1 0]                                                          
Second array:                                                          
[0 0 1 1 0 1]                                                          
Test above two arrays are equal or not!                                
False   

Python Code Editor:

Improve this sample solution and post your code through Disqus