【发布时间】:2018-09-24 14:53:23
【问题描述】:
我有一些数据(来自 HDF5 文件),我只想获取一些列。我尝试对数组进行切片,但得到了IndexError,我无法理解为什么。 有什么想法吗?
代码:
>>> type(x)
numpy.ndarray
>>> x
array([((1537445457, 517647), 0.45301986, 13.807418, 0.10681067, 6.856901 , 2.8895614, 15.341972, 2.8160472, 5.7942305, 67.95573, 2.5007493, 13.925896, 1.4587704, 6.1075644, 68.347534, 2.6885383, 15.334871, 0.31526774, 5.9454284, 0.713507 , nan, nan, nan, 0., 0., 0., 0., 0.),
((1537445457, 630955), 0.5777189 , 13.807683, 0.10421388, 6.8743234, 2.7194788, 14.866684, 2.753199 , 5.7411118, 68.38666, 3.0199409, 14.754977, 1.4933671, 5.7361865, 67.82245 , 3.4682775, 15.384485, 0.3508615 , 6.3675985, 0.31907487, nan, nan, nan, 0., 0., 0., 0., 0.)],
dtype=[('time', [('sec', '<u4'), ('usec', '<u4')]), ('0', '<f4'), ('1', '<f4'), ('2', '<f4'), ('3', '<f4'), ('4', '<f4'), ('5', '<f4'), ('6', '<f4'), ('7', '<f4'), ('8', '<f4'), ('9', '<f4'), ('10', '<f4'), ('11', '<f4'), ('12', '<f4'), ('13', '<f4'), ('14', '<f4'), ('15', '<f4'), ('16', '<f4'), ('17', '<f4'), ('18', '<f4'), ('19', '<f4'), ('20', '<f4'), ('21', '<f4'), ('22', '<f4'), ('23', '<f4'), ('24', '<f4'), ('25', '<f4'), ('26', '<f4')])
>>> x[0, [0, 1]]
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
<ipython-input-123-41118eda084a> in <module>()
----> 1 x[0, [0, 1]]
IndexError: too many indices for array
【问题讨论】:
-
看看
x.shape((2,))。它被视为一个两行数组,没有列。也许您需要重塑您的输入? -
@blacksite 你可能就在那儿……哦,天哪。从 HDF5 文件加载数据似乎并非易事。知道如何进行重塑吗?
-
是的,看起来我无法重塑数据,需要以良好的老式方式对其进行解析。皮塔饼,☹