Skip to content

Commit

Permalink
Try/except imports to deal with scipy datasets.
Browse files Browse the repository at this point in the history
  • Loading branch information
rossbar committed Jan 19, 2024
1 parent 8382ba0 commit 860ba4a
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions content/tutorial-svd.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,13 @@ After this tutorial, you should be able to:
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:

```{code-cell}
from scipy import datasets
# TODO: Rm try-except with scipy 1.10 is the minimum supported version
try:
from scipy.datasets import face
except ImportError: # Data was in scipy.misc prior to scipy v1.10
from scipy.misc import face
img = datasets.face()
img = face()
```

**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.
Expand Down

0 comments on commit 860ba4a

Please sign in to comment.