我有一些类型numpy。Float32,我想转储到一个json文件,所以我需要转换为浮动之前,但当我执行int(number)的变化是不正确的。
我有一个numpy列表。float32数字
试试这个:
array.astype(int)
有多种方法来提取"afloat32
:
In [86]: z=np.float32(1.234)
In [87]: z.tolist() # also used to make a list of Python numbers
Out[87]: 1.2339999675750732
In [88]: type(_)
Out[88]: float
In [89]: z.item() # also for a single item array
Out[89]: 1.2339999675750732
In [90]: type(_)
Out[90]: float
In [91]: float(z) # only for single item array
Out[91]: 1.2339999675750732
In [92]: type(_)
Out[92]: float
In [93]: int(z) # truncates the float
Out[93]: 1