Converting a c array to python list

Russell E. Owen rowen at cesmail.net
Fri Mar 2 16:09:09 EST 2007


In article <es66m4$cnr$1 at inews.gazeta.pl>,
 zefciu <zefirek at Speacock.Pau.Apoznan.Mpl> wrote:

> Hi!
> 
> I want to embed a function in my python application, that creates a
> two-dimensional array of integers and passes it as a list (preferably a
> list of lists, but that is not necessary, as the python function knows
> the dimensions of this array).  As I read the reference, I see, that I
> must first initialize a list object and then item-by-item put the values
> to the list.  Is there any faster way to do it?  And is it worth to
> implement?  The same problem is resolved in the current version by
> calling a smaller c function (that counts just one element of the array)
> many times.  Will it add much performance to the process?

My first thought is to use the numpy library since it is good at quickly 
creating large arrays (of any dimension) and you can easily get the data 
out as a list if you really need that (but are you sure you need that? 
You may be able to just use the numpy array directly).

It might help to have a clearer idea of why you want to do this. 

-- Russell

P.S. numarray or Numeric would also do the job. They are older, 
deprecated numeric libraries. numpy is recommended for new code.



More information about the Python-list mailing list