Array of objects in numpy.

P

Pepijn Kenter

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. 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. 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), the dot
function complained about an unsupported type. 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?

Any help would be appreciated.

Regards, Pepijn Kenter.
 
D

David M. Cooke

At some point said:
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.
 
P

Pepijn Kenter

David said:
including __r* variants too?


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


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).

No, I'm using numarray.
Don't know about that one. Maybe if you haven't added __rmul__ or
__radd__ to your class.

Thanks, I'll give it a try.

Pepijn.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,150
Latest member
MakersCBDReviews
Top