2017-09-27 54 views
2

數組我已經做了這個功能,它使用ctypes的創建具有指向指定地址的緩存協議的對象:構建從內存地址

import numpy as np 

def np_buffer_from_address(shape, dtype, address): 
    import ctypes 
    return np.ndarray(shape, dtype = dtype, buffer = ctypes.c_void_p.from_address(address)) 

但我想知道如果我能做到這一點不使用ctypes。如果你可以用numpy的直接做到這一點

+0

「地址」的來源是什麼?在鏈接中,我顯示你可以使用另一個數組的'.data'屬性。 https://stackoverflow.com/a/39377877/901925 – hpaulj

+1

'numpy.ctypes'可能有幫助; https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.ndarray.ctypes.html – hpaulj

回答