Alternative solution to 'Compare random arrays' plus an explanation
This commit is contained in:
@@ -387,8 +387,13 @@ np.add.reduce(Z)
|
||||
```python
|
||||
A = np.random.randint(0,2,5)
|
||||
B = np.random.randint(0,2,5)
|
||||
# Assuming identical shape of the arrays and a tolerance for the comparison of values
|
||||
equal = np.allclose(A,B)
|
||||
print(equal)
|
||||
|
||||
# Checking both the shape and the element values, no tolerance (values have to be exactly equal)
|
||||
equal = np.array_equal(A,B)
|
||||
print(equal)
|
||||
```
|
||||
|
||||
#### 43. Make an array immutable (read-only) (★★☆)
|
||||
|
||||
Reference in New Issue
Block a user