pass float array(list) parameter to C

marek.rocki at wp.pl marek.rocki at wp.pl
Mon Mar 17 10:59:04 EDT 2008


You can also do it with ctypes only; too bad it's not really well
documented. c_float is a type of a floating point number and it has *
operator defined, so that c_float*4 is a type of a 4-element array of
those numbers. So if you want to construct an array of floats from a
list of floats, you can do it like this:

from ctypes import c_float

x = [1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9]
float_array_type = c_float*len(x)
float_array = float_array_type(*x)
print float_array



More information about the Python-list mailing list