本文簡要介紹 python 語言中  numpy.char.chararray.ctypes  的用法。
- 用法:- char.chararray.ctypes
- 一個用於簡化數組與 ctypes 模塊交互的對象。 - 此屬性創建一個對象,使在使用 ctypes 模塊調用共享庫時更容易使用數組。返回的對象除其他外,還具有數據、形狀和步幅屬性(請參閱下麵的注釋),它們本身返回可用作共享庫的參數的 ctypes 對象。 - None:
 
- c: Python 對象
- 擁有屬性數據、形狀、步幅等。 
 
 - 參數:- 返回:- 注意:- 以下是記錄在“Guide to NumPy” 中的該對象的公共屬性(我們省略了未記錄的公共屬性以及記錄的私有屬性): - 指向數組內存區域的指針,作為 Python 整數。此內存區域可能包含未對齊的數據,或不正確的字節順序。內存區域甚至可能不可寫。將此屬性傳遞給任意C-code 時應尊重此數組的數組標誌和數據類型,以避免可能包括 Python 崩潰的問題。用戶當心!此屬性的值與 - self._array_interface_['data'][0]完全相同。- 請注意,與 - data_as不同,不會保留對數組的引用:像- ctypes.c_void_p((a + b).ctypes.data)這樣的代碼將導致指向已釋放數組的指針,應拚寫為- (a + b).ctypes.data_as(ctypes.c_void_p)
 - _ctypes。 數據:- (c_intp*self.ndim):長度為 self.ndim 的 ctypes 數組,其中基本類型是與此平台上的 - dtype('p')對應的 C-integer(請參閱- c_intp)。此 base-type 可能是- ctypes.c_int、- ctypes.c_long或- ctypes.c_longlong,具體取決於平台。 ctypes 數組包含底層數組的形狀。
 - _ctypes。 形狀:- (c_intp*self.ndim):長度為 self.ndim 的 ctypes 數組,其中基本類型與形狀屬性相同。此 ctypes 數組包含來自底層數組的步幅信息。此步長信息對於顯示必須跳轉多少字節才能到達數組中的下一個元素非常重要。 
 - _ctypes。 大步前進:- 將數據指針返回到特定的c-types 對象。例如,調用 - self._as_parameter_等效於- self.data_as(ctypes.c_void_p)。也許您想將數據用作指向浮點數據的 ctypes 數組的指針:- self.data_as(ctypes.POINTER(ctypes.c_double))。- 返回的指針將保留對數組的引用。 
 - _ctypes。 data_as (對象 ):- 將形狀元組作為其他 c-types 類型的數組返回。例如: - self.shape_as(ctypes.c_short)。
 - _ctypes。 shape_as (對象 ):- 將步幅元組作為其他 c-types 類型的數組返回。例如: - self.strides_as(ctypes.c_longlong)。
 - _ctypes。 strides_as (對象 ):- 如果 ctypes 模塊不可用,那麽數組對象的 ctypes 屬性仍然會返回一些有用的東西,但不會返回 ctypes 對象並且可能會引發錯誤。特別是,該對象仍將具有 - as_parameter屬性,該屬性將返回一個等於數據屬性的整數。- 例子:- >>> import ctypes >>> x = np.array([[0, 1], [2, 3]], dtype=np.int32) >>> x array([[0, 1], [2, 3]], dtype=int32) >>> x.ctypes.data 31962608 # may vary >>> x.ctypes.data_as(ctypes.POINTER(ctypes.c_uint32)) <__main__.LP_c_uint object at 0x7ff2fc1fc200> # may vary >>> x.ctypes.data_as(ctypes.POINTER(ctypes.c_uint32)).contents c_uint(0) >>> x.ctypes.data_as(ctypes.POINTER(ctypes.c_uint64)).contents c_ulong(4294967296) >>> x.ctypes.shape <numpy.core._internal.c_long_Array_2 object at 0x7ff2fc1fce60> # may vary >>> x.ctypes.strides <numpy.core._internal.c_long_Array_2 object at 0x7ff2fc1ff320> # may vary
相關用法
- Python numpy chararray.ctypes用法及代碼示例
- Python numpy chararray.copy用法及代碼示例
- Python numpy chararray.ndim用法及代碼示例
- Python numpy chararray.nbytes用法及代碼示例
- Python numpy chararray.setflags用法及代碼示例
- Python numpy chararray.flat用法及代碼示例
- Python numpy chararray.strides用法及代碼示例
- Python numpy chararray.view用法及代碼示例
- Python numpy chararray.imag用法及代碼示例
- Python numpy chararray.base用法及代碼示例
- Python numpy chararray.flatten用法及代碼示例
- Python numpy chararray.resize用法及代碼示例
- Python numpy chararray.sort用法及代碼示例
- Python numpy chararray.astype用法及代碼示例
- Python numpy chararray.real用法及代碼示例
- Python numpy chararray.T用法及代碼示例
- Python numpy chararray.transpose用法及代碼示例
- Python numpy chararray.fill用法及代碼示例
- Python numpy chararray.item用法及代碼示例
- Python numpy chararray.size用法及代碼示例
- Python numpy chararray.tostring用法及代碼示例
- Python numpy chararray.tobytes用法及代碼示例
- Python numpy chararray.itemsize用法及代碼示例
- Python numpy chararray.setfield用法及代碼示例
- Python numpy chararray.shape用法及代碼示例
注:本文由純淨天空篩選整理自numpy.org大神的英文原創作品 numpy.char.chararray.ctypes。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
