Array of objects in numpy.

David M. Cooke cookedm+news at physics.mcmaster.ca
Sun Aug 22 02:22:05 CEST 2004


At some point, Pepijn Kenter <pepijn.kenter at nospam.dlr.nl> wrote:

> Hi all.
>
> I'm new to python and want to use it for an assignment.
>
> I have succesfully implemented a galois field class including the _repr__,
> __mul__, __div__, __add__ and __sub__ methods.

including __r* variants too?

> Basically a galois field is
> an integer modulo a prime number. Now I want to make a matrix of these
> galois field objects using the numpy library. Constructing, printing and
> multiplying arrays of GF's works fine. However there are several functions
> that give problems, most importantly: dot, repeat. 
>
> I'm affraid I've forgotten my memmory stick with the code and error
> messages :-(, so I have to keep my question general.

I'm shooting in the dark here, as I presume you're using Numeric, as
opposed to numarray.

> If I recall correctly,
> the repeat function complained that my GF object didn't have the
> __getelem__ method implemented (IMO this should not be necessary),

My guess is that you're using Numeric.repeat incorrectly. Note that for
Numeric.repeat(a, repeats), a has to be array-like (more specifically,
array(a) can work).

> the dot function complained about an unsupported type.

Don't know about that one. Maybe if you haven't added __rmul__ or
__radd__ to your class.

> I know this is not the
> preffered way of asking for help on usenet but I'd like some feedback so I
> can work this weekend on the problem. I can use the dot & repeat with
> normal numpy arrays of floats, so I'm sure it is not due to my inexperience
> with python.
>
> Does anybody have experience using object arrays in numpy? Should I be able
> to get the dot & repeat function working, and what methods should my GF
> object support? Or are there known problems and pitfalls?

Have you tried numarray? The numarray.objects module handles object
arrays. It's being actively worked on, as opposed to Numeric.

-- 
|>|\/|<
/--------------------------------------------------------------------------\
|David M. Cooke
|cookedm(at)physics(dot)mcmaster(dot)ca



More information about the Python-list mailing list