我正在用python 3.7加载一个.npy文件。输出如下:
>>>import numpy as np
>>>dt = np.load('trajectories.npy')
>>>dt
array({'trajectories': array([[[729.78449821, 391.1702509],
[912.41666667, 315.5 ],
[832.0577381 , 325.83452381]],
...,
[[852.92 , 174.16253968],
[923.36053131, 347.92694497],
[878.89942529, 323.26652299]]]), video_path: 'myPath', frames_per_second: 28}, dtype = object)
考虑到我对numpy ndarrays不熟悉,dt对象在我看来就像一本字典。但是,当我尝试索引“轨迹”时,会收到一个错误:
>>>>dt['trajectories']
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
IndexError: only integers, slices (`:`), ellipsis (`...`), numpy.newaxis (`None`) and integer or boolean arrays are valid indices
>>>>dt.get('trajectories')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'numpy.ndarray' object has no attribute 'get'
当我把它当作数组时:
>>>dt[0]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
IndexError: too many indices for array
当我尝试将数组转换成元组时,我被告知数组是0-d。
发生什么事?