473,385 Members | 1,888 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Array of objects in numpy.

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.

Jul 18 '05 #1
2 3253
At some point, Pepijn Kenter <pe***********@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
Jul 18 '05 #2
David M. Cooke wrote:
At some point, Pepijn Kenter <pe***********@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).


No, I'm using numarray.
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.


Thanks, I'll give it a try.

Pepijn.

Jul 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Bo Peng | last post by:
Dear list, I am writing a Python extension module that needs a way to expose pieces of a big C array to python. Currently, I am using NumPy like the following: PyObject* res =...
4
by: TG | last post by:
Hi there ! I'm just starting to use Numeric here, and I'm wondering : how can I efficiently initialize every values of a N-dimensional array, given I don't know the number of dimensions ? I'm...
2
by: goetzie | last post by:
I am using Python 2.4.1 and Numeric 23.8 and running on Windows XP. I am passing a Numeric array of strings (objects) to a C Extension module using the following python code: import Numeric...
8
by: SpreadTooThin | last post by:
Basically I think the problem is in converting from a 32 bit integer to a 16 bit integer. I have two arrays: import array a = array.array('L', ) b = array.array('H', ) b = a
272
by: Peter Olcott | last post by:
http://groups.google.com/group/comp.lang.c++/msg/a9092f0f6c9bf13a I think that the operator() member function does not work correctly, does anyone else know how to make a template for making two...
3
by: Sean Davis | last post by:
I have a set of numpy arrays which I would like to save to a gzip file. Here is an example without gzip: b=numpy.ones(1000000,dtype=numpy.uint8) a=numpy.zeros(1000000,dtype=numpy.uint8) fd =...
3
by: knielsen73 | last post by:
Hi, I am a python newbie, trying to convert my IDL scripts to python. I am kind of stuck at the moment. I am reading in a 1-D data file with 2000 data points. I need to put them in a 3-D array...
2
by: Rick Giuly | last post by:
Hello All, Case 1 This generates an error, which makes sense because the argument should be a list of numbers: numpy.array(10,10) Case 2 This does not generate an error and the result is an...
3
by: Rüdiger Werner | last post by:
Hello! Out of curiosity and to learn a little bit about the numpy package i've tryed to implement a vectorised version of the 'Sieve of Zakiya'. While the code itself works fine it is...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.