Declaring an array of a specific size?
Author Message
Declaring an array of a specific size?

I need an integer array with 24 elements and I'm at a loss finding out
how to do this elegantly.

array.array("i", [0, ...., 0])

just can't be it. But what's the right way?

Michael

--
Michael Schuerig

http://www.*-*-*.com/

Thu, 05 Sep 2002 03:00:00 GMT
Declaring an array of a specific size?

Quote:
> I need an integer array with 24 elements and I'm at a loss finding out
> how to do this elegantly.

Would

array.array("i", 24 * [0])

do the trick?

Also, in the Numeric package, there is something that might help:

Quote:
>>> from Numeric import zeros
>>> zeros (24, 'i')

array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],'i')

Alex.

Thu, 05 Sep 2002 03:00:00 GMT
Declaring an array of a specific size?

Quote:

> > I need an integer array with 24 elements and I'm at a loss finding out
> > how to do this elegantly.

> Would

> array.array("i", 24 * [0])

> do the trick?

> Also, in the Numeric package, there is something that might help:

> >>> from Numeric import zeros >>> zeros (24, 'i') array([0, 0, 0, 0, 0, 0,
> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],'i') >>>

Yes, that does it. Thanks! But, I'm wondering, how would a newbie such
as I am, have found this?

Michael

--
Michael Schuerig

http://www.schuerig.de/michael/

Fri, 06 Sep 2002 03:00:00 GMT
Declaring an array of a specific size?

Quote:
> how would a newbie such as I am, have found this?

Well, you could read the documentation at python.org.  There is rather a
lot of it, though.  The documentation for the Numeric package is at
numpy.sourceforge.net.  I don't think I ever read about the '24 * [0]'
thing, I just tried it on the command line at one point, because it
seemed natural.

I'm something of a newbie myself.

Alex.

Fri, 06 Sep 2002 03:00:00 GMT
Declaring an array of a specific size?

Quote:

> > how would a newbie such as I am, have found this?

> Well, you could read the documentation at python.org.  There is rather a
> lot of it, though.

Actually, I have the docs installed on my system. But they didn't help
me with this specific question. I looked into the description of array
and searched the indexes for something that might be appropriate, but
found nothing useful.

Quote:
> The documentation for the Numeric package is at
> numpy.sourceforge.net.

Now(!) that I know that it exists, I found the docs included in the
python-numeric Debian package...

I must admit that I didn't invest any substantial time into Python, so
far. I was trying to do something in Perl, a language I've been using
for almost 10 years, but unfortunately only 3 times each year. This time
it was just killing me and thus I decided to go for python to keep my
sanity.

Michael

--
Michael Schuerig

http://www.schuerig.de/michael/

Sat, 07 Sep 2002 03:00:00 GMT

 Page 1 of 1 [ 5 post ]

Relevant Pages