Skip to content

Commit 4cb1d8c

Browse files
authored
mention np.errstate context manager in exercise 31.
1 parent e8ad2e1 commit 4cb1d8c

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

100 Numpy exercises.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,12 +282,19 @@ print(np.intersect1d(Z1,Z2))
282282
```python
283283
# Suicide mode on
284284
defaults = np.seterr(all="ignore")
285-
Z = np.ones(1)/0
285+
Z = np.ones(1) / 0
286286

287287
# Back to sanity
288288
_ = np.seterr(**defaults)
289289
```
290290

291+
An equivalent way, with a context manager:
292+
293+
```python
294+
with np.errstate(divide='ignore'):
295+
Z = np.ones(1) / 0
296+
```
297+
291298
#### 32. Is the following expressions true? (★☆☆)
292299

293300

0 commit comments

Comments
 (0)