我希望通过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在py3中是<U1,在运行我的最后一行代码时我得到了这个错误:
TypeError: Cannot cast array data from dtype('<U1') to dtype('S1') according to the rule 'safe'如果我在b = b.astype('S1')中添加py3,也会出现同样的错误。但是,b.dtype是|S1。
发布于 2018-10-23 02:42:17
尝试:
b = np.array(list(a.ljust(13)),dtype='S1')https://stackoverflow.com/questions/52931670
复制相似问题