Learning Scientific Programming with Python (2nd edition)
Q6.1.11: The dtypes of scalars and arrays
Question Q6.1.11
The dtype
np.uint8
represents an unsigned integer in 8 bits. Its value may therefore be in the range $0 - 255$. Explain the following behaviour:
In [x]: x = np.uint8(250)
In [x]: x * 2
Out[x]: 500
In [x]: x = np.array([250,], dtype=np.uint8)
In [x]: x * 2
Out[x]: array([244], dtype=uint8)