Alternative solution to 'Compare random arrays' plus an explanation
This commit is contained in:
parent
9e6559e6eb
commit
9b248dd3de
@ -855,8 +855,13 @@
|
||||
"source": [
|
||||
"A = np.random.randint(0,2,5)\n",
|
||||
"B = np.random.randint(0,2,5)\n",
|
||||
"# Assuming identical shape of the arrays and a tolerance for the comparison of values"
|
||||
"equal = np.allclose(A,B)\n",
|
||||
"print(equal)"
|
||||
"\n"
|
||||
"# Checking both the shape and the element values, no tolerance (values have to be exactly equal)"
|
||||
"equal = np.array_equal(A,B)"
|
||||
"print(equal)"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
@ -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) (★★☆)
|
||||
|
Loading…
x
Reference in New Issue
Block a user