ctypes - 没有形状的numpy数组?

Ale*_*ich 7 python arrays ctypes numpy dimensions

我使用python包装器来调用c ++ dll库的函数.一个ctype由dll库返回,我将其转换为numpy数组

score = np.ctypeslib.as_array(score,1) 
Run Code Online (Sandbox Code Playgroud)

但阵列没有形状?

score
>>> array(-0.019486344729027664)

score.shape
>>> ()

score[0]
>>> IndexError: too many indices for array
Run Code Online (Sandbox Code Playgroud)

如何从乐谱数组中提取双精度?

谢谢.

jpp*_*jpp 12

您可以通过索引访问0维数组中的数据[()].

例如,score[()]将检索数组中的基础数据.

  • 这是什么魔法? (3认同)
  • 或者,对于具有单个值的数组,“array.item()”将返回一个标量,无论其维度如何。`np.array(0).item() == np.atleast_3d(0).item()`。 (3认同)