Types 属性错误:';AstypeContext';对象没有属性';数据类型';
我想将sal_maps_hf的数据类型更改为nint8 soTypes 属性错误:';AstypeContext';对象没有属性';数据类型';,types,computer-vision,pytorch,h5py,Types,Computer Vision,Pytorch,H5py,我想将sal_maps_hf的数据类型更改为nint8 so sal_maps_hf.shape (11, 32, 32, 3) sal\u映射\u hf.dtype 数据类型('用于h5py.datasetastype方法的文档: sal_maps_hf.dtype dtype('<f4') sal_maps_hf = sal_maps_hf.astype(np.uint8) print(sal_maps_hf.dtype) 注意,这并没有直接显示astype的dtype。应用于n
sal_maps_hf.shape
(11, 32, 32, 3)
sal\u映射\u hf.dtype
数据类型('用于h5py.dataset
astype
方法的文档:
sal_maps_hf.dtype
dtype('<f4')
sal_maps_hf = sal_maps_hf.astype(np.uint8)
print(sal_maps_hf.dtype)
注意,这并没有直接显示astype
的dtype
。应用于numpy数组的astype
确实会生成一个新数组。但是使用h5py
的工作方式与此不同。假设sal_-maps\u-hf
是一个h5py数据集,下面是如何应用@hpualj对示例的回答:与sal_-maps_hf.astype(np.uint8);out=sal_maps_hf[:]
。然后当您签出out.dtype
时,您应该得到dtype('uint8')
。请注意,out
是从sal_maps_hf
数据集中读取的一个np.ndarray。
astype(dtype)
Return a context manager allowing you to read data as a particular type. Conversion is handled by HDF5 directly, on the fly:
>>> dset = f.create_dataset("bigint", (1000,), dtype='int64')
>>> with dset.astype('int16'):
... out = dset[:]
>>> out.dtype
dtype('int16')