Skip to content

Commit cfedc1a

Browse files
Copilotmmcky
andauthored
Update SciPy lecture: Fix outdated import statement for SciPy 1.15+ compatibility (#406)
* Initial plan * Update SciPy lecture: Fix outdated import statement for SciPy 1.15+ compatibility Co-authored-by: mmcky <[email protected]> * good suggestions, manual edit * fix fencing level * fix execution error --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: mmcky <[email protected]> Co-authored-by: mmcky <[email protected]>
1 parent 341ec14 commit cfedc1a

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

lectures/scipy.md

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,21 @@ kernelspec:
2323
```{index} single: Python; SciPy
2424
```
2525

26+
In addition to what’s in Anaconda, this lecture will need the following libraries:
27+
28+
```{code-cell} ipython3
29+
:tags: [hide-output]
30+
31+
!pip install --upgrade quantecon
32+
```
33+
34+
We use the following imports.
35+
36+
```{code-cell} ipython3
37+
import numpy as np
38+
import quantecon as qe
39+
```
40+
2641
## Overview
2742

2843
[SciPy](https://scipy.org/) builds on top of NumPy to provide common tools for scientific programming such as
@@ -49,26 +64,27 @@ In this lecture, we aim only to highlight some useful parts of the package.
4964

5065
SciPy is a package that contains various tools that are built on top of NumPy, using its array data type and related functionality.
5166

52-
In fact, when we import SciPy we also get NumPy, as can be seen from this excerpt the SciPy initialization file:
67+
````{note}
68+
In older versions of SciPy (`scipy < 0.15.1`), importing the package would also import NumPy symbols into the global namespace, as can be seen from this excerpt the SciPy initialization file:
5369
54-
```{code-cell} python3
55-
# Import numpy symbols to scipy namespace
70+
```python
5671
from numpy import *
5772
from numpy.random import rand, randn
5873
from numpy.fft import fft, ifft
5974
from numpy.lib.scimath import *
6075
```
6176
62-
However, it's more common and better practice to use NumPy functionality explicitly.
77+
However, it is better practice to use NumPy functionality explicitly.
6378
64-
65-
```{code-cell} python3
79+
```python
6680
import numpy as np
67-
import quantecon as qe
6881
6982
a = np.identity(3)
7083
```
7184
85+
More recent versions of SciPy (1.15+) no longer automatically import NumPy symbols.
86+
````
87+
7288
What is useful in SciPy is the functionality in its sub-packages
7389

7490
* `scipy.optimize`, `scipy.integrate`, `scipy.stats`, etc.

0 commit comments

Comments
 (0)