这篇文章我们玩玩numpy的数值数据类型转换
导入numpy
>>> import numpy as np
一、随便玩玩
生成一个浮点数组
>>> a = np.random.random(4)
看看信息
>>>a
array([0.0945377 , 0.52199916, 0.62490646, 0.21260126])>>>a.dtype
dtype('float64')>>>a.shape
(4,)
改变dtype,发现数组长度翻倍!
>>> a.dtype = 'float32'
>>>a
array([3.65532693e+20, 1.43907535e+00, -3.31994873e-25,1.75549972e+00, -2.75686653e+14, 1.78122652e+00,-1.03207532e-19, 1.58760118e+00], dtype=float32)>>>a.shape
(8,)
改变dtype,数组长度再次翻倍!
>>> a.dtype = 'float16'
>>>a
array([-9.58442688e-05, 7.19000000e+02, 2.38159180e-01,1.92968750e+00, nan, -1.66034698e-03,-2.63427734e-01, 1.96875000e+00, -1.07519531e+00,-1.19625000e+02, nan, 1.97167969e&#