我有一把标准的np.array
,型号是np.int32
:
idx = array([ 607, 638, 639, ..., 9279, 9317, 9318], dtype=int32)
个
为了确保int32
实际上是np.int32
,我使用以下命令进行验证:
>>> type(idx[0])
<class 'numpy.int32'>
为了稍后使用这个数组,我需要它们的类型为int
(原因是我希望使用cppyy
来对a std::vector<T>
进行DO索引,这似乎对索引类型很严格).因此,我认为我能做到
>>> idx2 = idx.astype(int)
个
但这给了我们
>>> type(idx2[0])
<class 'numpy.int64'>
我一定要用这样的东西吗?
>>> idx3 = [int(k) for k in idx]
>>> type(idx3[0])
<class 'int'>
有什么建议吗?
Update 1:也许这将提供更多关于std::vector
的索引的信息:
>>> v[idx[0]]
*** TypeError: an integer is required
鉴于
>>> v[int(idx[0])]
<cppyy.gbl.std.vector<double> object at 0x559a9a8845a8>
Update 2:对我来说,转换为List是令人满意的,我已经接受了这个答案.