我想通过pyhdf在hdf中保存一些东西作为变量。
这是我的代码:
import numpy as np
from pyhdf.SD import *
var = 'PRESSURE_INDEPENDENT_SOURCE'
vartype = 4
hdf4 = SD('./a.hdf', 2 | 4)
dset = hdf4.create(var, vartype, (1,13))
a = 'AFGL_1976'
b = np.array([list(a.ljust(13))])
dset[:] = b
它适用于 py2 并且b.type是|S1.
但是,b.dtype是<U1在PY 3和运行我的代码的最后一排,当我得到这个错误:
TypeError: Cannot cast array data from dtype('<U1') to dtype('S1') according to the rule 'safe'
如果我b = b.astype('S1')在 py3 中添加,也会出现同样的错误。但是,b.dtype是|S1。
BIG阳
相关分类