[Numpy-discussion] Re: numarray.objects missing in documentation

Faheem Mitha faheem at email.unc.edu
Sun Mar 14 09:21:02 EST 2004


On Sun, 14 Mar 2004 09:55:52 -0500, Todd Miller <jmiller at stsci.edu> wrote:
> On Sun, 2004-03-14 at 00:26, Faheem Mitha wrote:
>> Dear People,
>> 
>> I'm posting this to gmane.comp.python.numeric.general. I am not sure
>> what mailing list this corresponds to. I earlier tried to post this to
>> the mailing list mentioned in the numarray documentation
>> (numpy at lists.sourceforge.net), but it bounced.
>> 
>> I don't see numarray.objects listed in
>> http://stsdas.stsci.edu/numarray/numarray-0.9.html/genindex.html
>
> The section on object arrays has yet to be written.  What is it that you
> want to know?

Thanks for the quick reply. I'm trying to make an array of python
objects as follows. Specifically, given a user defined class, I want
to creata an array of instances of that class.

Consider the following class.

class cell:
    def setrow(self,row):
        self.row = row
    def setcol(self,col):
        self.col = col
    ...

I create an "empty" cell.

empcell = cell()

Now I want to create an array of objects identical to empcell, and
later initialize them.

I tried stuff along the lines of

******************************************************************
import string
from numarray import *

empcell = cell()

base = [empcell]

mat = fromlist(base,shape=(2,2))
******************************************************************

But the

mat = fromlist(base,shape=(2,2))

line fails with

AttributeError: cell instance has no attribute '__len__'

Similar things fail with the same error message. No doubt I'm doing
something stupid, but would someone please enlighten me?

I got the fromlist command from

>>> help("numarray.objects")

I was a bit disconcerted to find on trying to run the first example
from the help page that I got

>>> a = fromlist(["t","u","w"])
...
TypeError: Expecting a python numeric type, got something else.

What am I doing wrong?

I'm running

ii  python                    2.3.3-5                   An interactive
high-level object-oriented language (default versio
ii  python-numarray           0.8.1-1                   An array
processing package modelled after Python-Numeric
ii  python-numeric            23.1-1                    Numerical
(matrix-oriented) Mathematics for Python

on Debian sarge.

Thanks in advance and sorry for the long-winded message.

                                                          Faheem.





More information about the NumPy-Discussion mailing list