Alternative solution to 'Compare random arrays' plus an explanation

This commit is contained in:
ibah 2016-08-25 14:52:59 +02:00
parent 9e6559e6eb
commit 9b248dd3de
2 changed files with 10 additions and 0 deletions

View File

@ -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)"
]
},
{

View File

@ -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) (★★☆)