AttributeError: у объекта «AstypeContext» нет атрибута «dtype» - PullRequest
0 голосов
/ 07 января 2020
sal_maps_hf.shape
(11, 32, 32, 3)

Я хочу изменить dtype sal_maps_hf на nint8, так

sal_maps_hf.dtype
dtype('<f4')

sal_maps_hf = sal_maps_hf.astype(np.uint8)
print(sal_maps_hf.dtype)

-------------------------------------- ------------------------------------- AttributeError Traceback (последний вызов был последним) в ---- > 1 print (sal_maps_hf.dtype)

AttributeError: у объекта 'AstypeContext' нет атрибута 'dtype'

1 Ответ

0 голосов
/ 07 января 2020

Документы для h5py.dataset astype метода:

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')

Обратите внимание, это не показывает dtype astype напрямую. astype, примененный к массиву numpy, создает новый массив. Но с h5py не совсем так работает.

...