Cast np.array([300, 20, 30]) down to uint8

NumPy · from dtypes, precision and casting

int8/16/32/64uint8float32/64overflow.astypepromotionnp.iinfonp.isclose

Putting the kettle on…

Starting up…

Exercise 1

Cast np.array([300, 20, 30]) down to uint8. One of those values doesn't fit in a byte — run it and see what it becomes.

your answer
stuck? the lesson behind it
dtypes, precision and casting
Fixed-width boxes — and every surprise that follows from them.