Movatterモバイル変換


[0]ホーム

URL:


SciPy

C-Types Foreign Function Interface (numpy.ctypeslib)

numpy.ctypeslib.as_array(obj,shape=None)[source]

Create a numpy array from a ctypes array or POINTER.

The numpy array shares the memory with the ctypes object.

The shape parameter must be given if converting from a ctypes POINTER.The shape parameter is ignored if converting from a ctypes array

numpy.ctypeslib.as_ctypes(obj)[source]

Create and return a ctypes object from a numpy array. Actuallyanything that exposes the __array_interface__ is accepted.

numpy.ctypeslib.ctypes_load_library(*args,**kwds)[source]

ctypes_load_library is deprecated, useload_library instead!

It is possible to load a library using >>> lib = ctypes.cdll[<full_path_name>]

But there are cross-platform considerations, such as library file extensions,plus the fact Windows will just load the first library it finds with that name. NumPy supplies the load_library function as a convenience.

Parameters:
libname:str

Name of the library, which can have ‘lib’ as a prefix,but without an extension.

loader_path:str

Where the library can be found.

Returns:
ctypes.cdll[libpath]:library object

A ctypes library object

Raises:
OSError

If there is no library with the expected extension, or the library is defective and cannot be loaded.

numpy.ctypeslib.load_library(libname,loader_path)[source]

It is possible to load a library using >>> lib = ctypes.cdll[<full_path_name>]

But there are cross-platform considerations, such as library file extensions,plus the fact Windows will just load the first library it finds with that name. NumPy supplies the load_library function as a convenience.

Parameters:
libname:str

Name of the library, which can have ‘lib’ as a prefix,but without an extension.

loader_path:str

Where the library can be found.

Returns:
ctypes.cdll[libpath]:library object

A ctypes library object

Raises:
OSError

If there is no library with the expected extension, or the library is defective and cannot be loaded.

numpy.ctypeslib.ndpointer(dtype=None,ndim=None,shape=None,flags=None)[source]

Array-checking restype/argtypes.

An ndpointer instance is used to describe an ndarray in restypesand argtypes specifications. This approach is more flexible thanusing, for example,POINTER(c_double), since several restrictionscan be specified, which are verified upon calling the ctypes function.These include data type, number of dimensions, shape and flags. If agiven array does not satisfy the specified restrictions,aTypeError is raised.

Parameters:
dtype:data-type, optional

Array data-type.

ndim:int, optional

Number of array dimensions.

shape:tuple of ints, optional

Array shape.

flags:str or tuple of str

Array flags; may be one or more of:

  • C_CONTIGUOUS / C / CONTIGUOUS
  • F_CONTIGUOUS / F / FORTRAN
  • OWNDATA / O
  • WRITEABLE / W
  • ALIGNED / A
  • WRITEBACKIFCOPY / X
  • UPDATEIFCOPY / U
Returns:
klass:ndpointer type object

A type object, which is an_ndtpr instance containingdtype, ndim, shape and flags information.

Raises:
TypeError

If a given array does not satisfy the specified restrictions.

Examples

>>>clib.somefunc.argtypes=[np.ctypeslib.ndpointer(dtype=np.float64,...ndim=1,...flags='C_CONTIGUOUS')]...>>>clib.somefunc(np.array([1,2,3],dtype=np.float64))...

Previous topic

numpy.core.defchararray.chararray.zfill

Next topic

Datetime Support Functions

Quick search

  • © Copyright 2008-2018, The SciPy community.
  • Last updated on Jul 24, 2018.
  • Created usingSphinx 1.6.6.

[8]ページ先頭

©2009-2025 Movatter.jp