嘿,我得到了这个代码,我用它来把numpy2d数组转换成ctype双指针。你知道吗
import ctypes as ct
import numpy as np
arr = np.empty([500, 500], dtype=np.uint8)
UI8Ptr = ct.POINTER(ct.c_uint8)
UI8PtrPtr = ct.POINTER(UI8Ptr)
ct_arr = np.ctypeslib.as_ctypes(arr)
UI8PtrArr = UI8Ptr * ct_arr._length_
ct_ptr = ct.cast(UI8PtrArr(*(ct.cast(row, UI8Ptr) for row in ct_arr)), UI8PtrPtr)
我怎样才能将ct\U ptr投射回numpy 2d阵列?你知道吗
注意:这是[SO]: How to pass a 2d array from Python to C?的后续行动。你知道吗
一种方法是经历以下状态:
自动出现2个观察结果:
代码00.py:
输出:
有关此主题的详细信息,请查看[SO]: Numpy error when converting array of ctypes types to void pointer (@CristiFati's answer)。你知道吗
相关问题 更多 >
编程相关推荐