[Numpy-discussion] trouble ingegrating Numpy arrays into a class statement
Paul F. Dubois
paul at pfdubois.com
Mon Dec 24 10:35:02 CST 2001
Without asking why in the world you would want to do this:
class Cond:
x1=0
y1=0
z1=0
x2=0
y2=0
z2=0
DelX=0
DelY=0
DelZ=0
wire = map(lambda dummy: Cond(), range(20))
print wire[10].x1
This makes a list. If you really INSIST on a Numeric array, add
import Numeric
wire = Numeric.array(wire)
But this will be an array of type O. If your real concern is that the
size will
be huge, you might want to make arrays out of each member instead. You
have your choice of making the syntax wire.x1[10] or wire[10].x1, but
the latter requires additional technique.
Also I doubt that you mean what you said. If each instance is to have
its own values, and
the ones above are just the initial values, it is much more proper to
do:
class Cond:
def __init__ (self, **kw):
d = { 'x1':0, ... put them all here }
d.update(kw)
for k, v in d.items():
setattr(self, k, v)
That allows you to make instances all these way: Cond(), Cond(x1=4),
Cond(x1=1,y2=1),
Cond(x1=0
y1=0
z1=0
x2=0
y2=0
z2=0
DelX=0
DelY=0
DelZ=0
)
-----Original Message-----
From: numpy-discussion-admin at lists.sourceforge.net
[mailto:numpy-discussion-admin at lists.sourceforge.net] On Behalf Of Rob
Sent: Monday, December 24, 2001 9:37 AM
To: numpy-discussion at lists.sourceforge.net
Subject: [Numpy-discussion] trouble ingegrating Numpy arrays into a
class statement
I have this Class:
class Cond:
x1=0
y1=0
z1=0
x2=0
y2=0
z2=0
DelX=0
DelY=0
DelZ=0
What I want is for Cond to be a Numpy array of 20 values, each with the
above members. Thus I could say in a statement:
wire=Cond
a= wire[10].x1
b= wire[5].z2 etc...
How can I go about this? Thanks, Rob. and Merry Christmas!!!!!!!
ps. this is for an FEM-MOM grid generator
--
The Numeric Python EM Project
www.pythonemproject.com
_______________________________________________
Numpy-discussion mailing list Numpy-discussion at lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/numpy-discussion
More information about the Numpy-discussion
mailing list