Skip to content

Commit 4623913

Browse files
authored
Merge pull request #86 from HealthBioscienceIDEAS/km/update-last-image-exercise
Update exercise to mention OverflowError
2 parents 8e0d7fe + 1d395be commit 4623913

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

episodes/what-is-an-image.md

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -393,9 +393,11 @@ and _overflow_.
393393
value. For example, storing 1000 in a `uint8` image may result in 255 being
394394
stored instead (the max value)
395395

396-
- Overflow: For NumPy arrays, values outside the valid range are
397-
'wrapped around' to give the new result. For example, storing 256 in a `uint8`
398-
image (max 255) would give 0, 257 would give 1 and so on...
396+
- Overflow: For NumPy arrays, values outside the valid range may be
397+
'wrapped around' or create an `OverflowError`, depending on what version of
398+
NumPy is installed. Older versions of NumPy may wrap the values around, so
399+
storing 256 in a `uint8` image (max 255) would give 0, 257 would give 1 and so
400+
on... Newer versions of NumPy will raise an `OverflowError`.
399401

400402
Clipping and overflow result in data loss - you can't get the original values
401403
back! So it's always good to keep the data type in mind when doing image
@@ -530,19 +532,19 @@ you should see the one bright pixel you just created.
530532
```python
531533

532534
image[15, 10] = 300
533-
viewer.layers["human_mitosis"].refresh()
534-
535-
print(image[15, 10])
536535
```
537536

538-
```output
537+
```error
539538
540-
44
541-
```
539+
OverflowError Traceback (most recent call last)
540+
Cell In[8], line 1
541+
----> 1 image[15, 10] = 300
542542
543-
The new value is not correct. This is because 300 exceeds the maximum value for
544-
this 8-bit image (max 255). The value therefore overflows and 'wraps around' to
545-
give 44 - an incorrect value.
543+
OverflowError: Python integer 300 out of bounds for uint8
544+
```
545+
An `OverflowError` occurs when you try to update this pixel value.
546+
This is because 300 exceeds the maximum value for
547+
this 8-bit image (max 255).
546548

547549
:::::::::::::::::::::::::::::::::
548550

0 commit comments

Comments
 (0)