我有一個不包含數據值的numpy數組。我掩蓋那些沒有數據值,使他們不使用影響我算了一筆賬:memove一個蒙面數組 - python
array = numpy.ma.masked_values(array, options['ndv'], copy=False)
然後我用的memmove使用的numpy的陣列進入一個共享的ctypes陣列:
def ndarray_to_shmem(array):
""" Converts a numpy.ndarray to a multiprocessing.Array object.
The memory is copied, and the array is flattened.
"""
arr = array.reshape((-1,))
data = RawArray(_numpy_to_ctypes[array.dtype.type],
arr.size)
ctypes.memmove(data, array.data[:], len(array.data))
return data
它返回以下堆棧跟蹤:
ctypes.memmove(data, array.data[:], len(array.data))
ctypes.ArgumentError: argument 2: <type 'exceptions.TypeError'>: wrong type
是否有可能使用的memmove到掩蔽陣列移動到共享,ctypes的數組?
當您移動蒙版陣列時,究竟發生了什麼?你是否希望只獲得沒有被掩蓋的價值觀?無價值的條目應該轉換爲南? – Luke 2012-08-07 23:32:43
轉換爲NaN。然後在執行一些計算後,我將轉換回輸入的無數據值。 – Jzl5325 2012-08-08 00:04:53