toNdarray

Utility routine used to convert a Python ctypes array to a NumPy ndarray.

Synopsis

toNdarray (ctypes_array, shape)

Required Arguments

ctypes ctypes_array[] (Input)
Floating point ctypes array.
tuple shape[] (Input)
A tuple containing the size of each dimension in ctypes_array.

Return Value

A NumPy ndarray with a copy of the data from the ctypes array.

Optional Arguments

dtype (type)
Specify the type of the ndarray desired. The default is double.

Description

This routine is used to convert a Python ctypes array to a NumPy ndarray. This is only needed inside user defined functions. Arrays passed to user defined functions are always passed in a ctypes array, which can be indexed as a 1D array using standard notation with braces – []. However if you wish to pass this array to another routine which expects an ndarray as input, including other PyIMSL functions, then this utility may be used to convert the array.

Note that this utility is imported from pyimsl.util.imslConvert.

Example

For an example of using this routine see the example for the PyIMSL math routine linSolDefCg, the relevant part of which is shown here in the user supplied function:

from pyimsl.util.imslConvert import toCtypes
from pyimsl.util.imslConvert import toNdarray
...
def amultp (p,z):
            ptmp = toNdarray(p, (n))
            ztmp=matMulRect ("A*x",
                                  aMatrix = a,
                                  xVector = ptmp)
            toCtypes(ztmp, z)