Skip to main content
 首页 » 编程设计

python : Change datatype of hdf5 array

2025年04月02日14java哥

我有如下的 hdf5 数组:

>>> a = np.array([5,8]) 
>>> f = h5py.File('try.hdf5') 
>>> f['try'] = a 
>>> f['try'] 
<HDF5 dataset "try": shape (2,), type "<i4"> 

我想将 f['try'] 的数据类型更改为 float64。怎么做?

a = a.astype('float64')可以用于 numpy,但我不知道用于 hdf5。

请您参考如下方法:

HDF5 User's Guide (第 6.3.2 节)清楚地说:

The datatype of a dataset can never be changed.

另见 this问题。