Merge pull request #29 from ev-br/patch-1
mention `np.errstate` context manager in exercise 31.
This commit is contained in:
@@ -477,8 +477,8 @@
|
|||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"Z = np.dot(np.ones((5,3)), np.ones((3,2)))\n",
|
"Z = np.dot(np.ones((5,3)), np.ones((3,2)))\n",
|
||||||
"print(Z)",
|
"print(Z)\n",
|
||||||
"\n\n",
|
"\n",
|
||||||
"# Alternative solution, in Python 3.5 and above\n",
|
"# Alternative solution, in Python 3.5 and above\n",
|
||||||
"Z = np.ones((5,3)) @ np.ones((3,2))"
|
"Z = np.ones((5,3)) @ np.ones((3,2))"
|
||||||
]
|
]
|
||||||
@@ -628,10 +628,16 @@
|
|||||||
"source": [
|
"source": [
|
||||||
"# Suicide mode on\n",
|
"# Suicide mode on\n",
|
||||||
"defaults = np.seterr(all=\"ignore\")\n",
|
"defaults = np.seterr(all=\"ignore\")\n",
|
||||||
"Z = np.ones(1)/0\n",
|
"Z = np.ones(1) / 0\n",
|
||||||
"\n",
|
"\n",
|
||||||
"# Back to sanity\n",
|
"# Back to sanity\n",
|
||||||
"_ = np.seterr(**defaults)"
|
"_ = np.seterr(**defaults)\n",
|
||||||
|
"\n",
|
||||||
|
"An equivalent way, with a context manager:\n",
|
||||||
|
"\n",
|
||||||
|
"```python\n",
|
||||||
|
"with np.errstate(divide='ignore'):\n",
|
||||||
|
" Z = np.ones(1) / 0"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -2334,7 +2340,7 @@
|
|||||||
"name": "python",
|
"name": "python",
|
||||||
"nbconvert_exporter": "python",
|
"nbconvert_exporter": "python",
|
||||||
"pygments_lexer": "ipython3",
|
"pygments_lexer": "ipython3",
|
||||||
"version": "3.5.2"
|
"version": "3.5.1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"nbformat": 4,
|
"nbformat": 4,
|
||||||
|
|||||||
@@ -282,12 +282,19 @@ print(np.intersect1d(Z1,Z2))
|
|||||||
```python
|
```python
|
||||||
# Suicide mode on
|
# Suicide mode on
|
||||||
defaults = np.seterr(all="ignore")
|
defaults = np.seterr(all="ignore")
|
||||||
Z = np.ones(1)/0
|
Z = np.ones(1) / 0
|
||||||
|
|
||||||
# Back to sanity
|
# Back to sanity
|
||||||
_ = np.seterr(**defaults)
|
_ = np.seterr(**defaults)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
An equivalent way, with a context manager:
|
||||||
|
|
||||||
|
```python
|
||||||
|
with np.errstate(divide='ignore'):
|
||||||
|
Z = np.ones(1) / 0
|
||||||
|
```
|
||||||
|
|
||||||
#### 32. Is the following expressions true? (★☆☆)
|
#### 32. Is the following expressions true? (★☆☆)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user