When converting an np.array to uint8 using astype the type of an element of the array doesn't change.
>>> x = np.array([[1.0, 2.3], [1.3, 2.9]])
>>> x.astype(uint8)
array([[1, 2],
[1, 2]], dtype=uint8)
>>> type(x[0,0])
<type 'numpy.float64'>
Why the element is still float64 and not uint8?
astype
returns a copy of the origin array.
Use x = x.astype(uint8)
instead
astype returns a copy of an array, so you must assign it:
x = x.astype(uint8)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With