Skip to content

Commit 9b248dd

Browse files
committed
Alternative solution to 'Compare random arrays' plus an explanation
1 parent 9e6559e commit 9b248dd

2 files changed

Lines changed: 10 additions & 0 deletions

File tree

100 Numpy exercises.ipynb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -855,8 +855,13 @@
855855
"source": [
856856
"A = np.random.randint(0,2,5)\n",
857857
"B = np.random.randint(0,2,5)\n",
858+
"# Assuming identical shape of the arrays and a tolerance for the comparison of values"
858859
"equal = np.allclose(A,B)\n",
859860
"print(equal)"
861+
"\n"
862+
"# Checking both the shape and the element values, no tolerance (values have to be exactly equal)"
863+
"equal = np.array_equal(A,B)"
864+
"print(equal)"
860865
]
861866
},
862867
{

100 Numpy exercises.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,8 +387,13 @@ np.add.reduce(Z)
387387
```python
388388
A = np.random.randint(0,2,5)
389389
B = np.random.randint(0,2,5)
390+
# Assuming identical shape of the arrays and a tolerance for the comparison of values
390391
equal = np.allclose(A,B)
391392
print(equal)
393+
394+
# Checking both the shape and the element values, no tolerance (values have to be exactly equal)
395+
equal = np.array_equal(A,B)
396+
print(equal)
392397
```
393398

394399
#### 43. Make an array immutable (read-only) (★★☆)

0 commit comments

Comments
 (0)