Alternative solution to 'Compare random arrays' plus an explanation
This commit is contained in:
@@ -855,8 +855,13 @@
|
|||||||
"source": [
|
"source": [
|
||||||
"A = np.random.randint(0,2,5)\n",
|
"A = np.random.randint(0,2,5)\n",
|
||||||
"B = 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",
|
"equal = np.allclose(A,B)\n",
|
||||||
"print(equal)"
|
"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
|
```python
|
||||||
A = np.random.randint(0,2,5)
|
A = np.random.randint(0,2,5)
|
||||||
B = 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)
|
equal = np.allclose(A,B)
|
||||||
print(equal)
|
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) (★★☆)
|
#### 43. Make an array immutable (read-only) (★★☆)
|
||||||
|
|||||||
Reference in New Issue
Block a user