【发布时间】:2019-03-26 15:58:45
【问题描述】:
我想通过 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'
如果我在 py3 中添加b = b.astype('S1'),也会出现同样的错误。但是,b.dtype 是 |S1。
【问题讨论】:
标签: python python-3.x python-2.7 typeerror pyhdf