Embedding Python in C

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Tue Jun 5 23:44:52 EDT 2007


En Tue, 05 Jun 2007 03:41:19 -0300, <mistabean at gmail.com> escribió:

> On 5 Jun., 01:32, "Gabriel Genellina" <gagsl-... at yahoo.com.ar> wrote:

>> Yes, it appears that you are building a plain list but your code is
>> expecting another kind of object. I'm unfamiliar with Numeric arrays, if
>> that is what you need; perhaps someone else can help, or ask again in a
>> Numeric-specific list.
>>
> yeah, i was looking at am array full of numbers. import numpy,scipy,
> maybe pylab too while i was testing out the function over at a python
> shell, make a linspace, sin it, and then call the function (which also
> is from the scipy cookbook). Is numeric arrays (or ndarray) unlike
> normal listing then? Since I started off programming in C, I am having
> a bit of a confusion identifiying the different type of arrays,
> listing and tuples and such... (since it's just "build an array of
> type so and so, and pass it over" ^^;;)

I've seen that you have already solved your main problem, but anyway I'll  
try to reduce your confusion a little...
Python lists and tuples are "generic" containers: both can contain any  
kind of object, and each item may be of a different type: (1, 2.0, 3+0j,  
"four", u"Fünf", file("six")) is a tuple containing 6 items, all of  
different types. Tuples are immutable, lists can be modified.
There is a price for such flexibility: memory and time overhead. When you  
don't require flexibility, you don't have to pay the price; Python already  
provides simple array objects (a flat container where ALL items are of the  
same type) and Numeric&Co support more array types and different floating  
point numbers.
Those arrays are not the same thing as lists/tuples - altough they share a  
very similar interfase.

-- 
Gabriel Genellina




More information about the Python-list mailing list