arrays in python

K

Kermit Rose

From: Kermit Rose
Date: 02/10/06 17:36:34
To: (e-mail address removed)
Subject: Arrays


Hello.

I want to write a program in python using integer arrays.

I wish to calculate formulas using 200 digit integers.

I could not find any documentation in python manual about declaring arrays.

I searched the internet

and found an example that said I must declare

from Numeric import *


and I downloaded a numerical python extension,

but still have not found a way to declare an array of given length.

The zeros function always gives me an error message.


Kermit < (e-mail address removed) >
 
S

Steven D'Aprano

I want to write a program in python using integer arrays.

I wish to calculate formulas using 200 digit integers.

Must the integers have exactly 200 digits? If you multiply one of these
200-digit integers by ten, should it silently overflow, raise an
exception, or become a 201-digit integer?

[snip]
The zeros function always gives me an error message.

Oh, don't tell me, I love playing guessing games!

Is it a SyntaxError?
 
?

=?ISO-8859-1?Q?Sch=FCle_Daniel?=

I want to write a program in python using integer arrays.

you can :)

I wish to calculate formulas using 200 digit integers.

no problem
I could not find any documentation in python manual about declaring arrays.

I searched the internet

read here
http://diveintopython.org/native_data_types/lists.html

maybe list are what you are looking for
and found an example that said I must declare

from Numeric import *

yes, one can use Numeric for this taks too
and I downloaded a numerical python extension,

but still have not found a way to declare an array of given length.

The zeros function always gives me an error message.
>>> import Numeric as N, random as rand
>>> nums = [33 ** rand.randint(10,100) for i in range(200)]
>>> len(nums) 200
>>> nums[0] 1666465812864030391541732975677083441749008906546726522024522041932256405404932170047036994592860856233379702595619607481259213235163454890913L
>>>
>>> a = N.array(nums)
>>> len(a) 200
>>> a[0] 1666465812864030391541732975677083441749008906546726522024522041932256405404932170047036994592860856233379702595619607481259213235163454890913L
>>>


by the way, you know you can use interactive Python iterpreter
and there is dir and help function
['__copy__', '__deepcopy__', 'astype', 'byteswapped', 'copy',
'iscontiguous', 'itemsize', 'resize', 'savespace', 'spacesaver',
'tolist', 'toscalar', 'tostring', 'typecode']['__add__', '__class__', '__contains__', '__delattr__', '__delitem__',
'__delslice__', '__doc__', '__eq__', '__ge__', '__getattribute__',
'__getitem__', '__getslice__', '__gt__', '__hash__', '__iadd__',
'__imul__', '__init__', '__iter__', '__le__', '__len__', '__lt__',
'__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__',
'__repr__', '__reversed__', '__rmul__', '__setattr__', '__setitem__',
'__setslice__', '__str__', 'append', 'count', 'extend', 'index',
'insert', 'pop', 'remove', 'reverse', 'sort']
Regards, Daniel
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top