Python:更改dask数组的dtype

时间:2016-03-29 05:31:23

标签: python dask

下面是一个dask数组

>>> import dask.array as da
>>> x = da.random.normal(5,2,size=(3,3),chunks=(1,1))
>>> x
dask.array<da.rand..., shape=(3, 3), dtype=float64, chunksize=(1, 1)>

我想将dtype更改为x的float96。怎么办?

1 个答案:

答案 0 :(得分:2)

通常,您可以使用.astype(...)方法更改NumPy或Dask数组的dtype。

x = x.astype(...)

然而,遗憾的是,NumPy和Dask.array都不支持float96

In [1]: import numpy as np

In [2]: np.float
np.float     np.float16   np.float64   np.floating  
np.float128  np.float32   np.float_    

In [2]: np.array(1, dtype='float96')
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-2-50670c2e1bb5> in <module>()
----> 1 np.array(1, dtype='float96')

TypeError: data type "float96" not understood