Skip to content

Commit 0164e42

Browse files
rossbarbsipocz
andcommitted
Try/except imports to deal with scipy datasets.
Co-authored-by: Brigitta Sipőcz <[email protected]>
1 parent 8382ba0 commit 0164e42

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

content/tutorial-svd.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,13 @@ After this tutorial, you should be able to:
3838
In this tutorial, we will use a [matrix decomposition](https://en.wikipedia.org/wiki/Matrix_decomposition) from linear algebra, the Singular Value Decomposition, to generate a compressed approximation of an image. We'll use the `face` image from the [scipy.datasets](https://docs.scipy.org/doc/scipy/reference/datasets.html) module:
3939

4040
```{code-cell}
41-
from scipy import datasets
41+
# TODO: Rm try-except with scipy 1.10 is the minimum supported version
42+
try:
43+
from scipy.datasets import face
44+
except ImportError: # Data was in scipy.misc prior to scipy v1.10
45+
from scipy.misc import face
4246
43-
img = datasets.face()
47+
img = face()
4448
```
4549

4650
**Note**: If you prefer, you can use your own image as you work through this tutorial. In order to transform your image into a NumPy array that can be manipulated, you can use the `imread` function from the [matplotlib.pyplot](https://matplotlib.org/api/_as_gen/matplotlib.pyplot.html#module-matplotlib.pyplot) submodule. Alternatively, you can use the [imageio.imread](https://imageio.readthedocs.io/en/stable/userapi.html#imageio.imread) function from the `imageio` library. Be aware that if you use your own image, you'll likely need to adapt the steps below. For more information on how images are treated when converted to NumPy arrays, see [A crash course on NumPy for images](https://scikit-image.org/docs/stable/user_guide/numpy_images.html) from the `scikit-image` documentation.

0 commit comments

Comments
 (0)