arrays in python
Schüle Daniel
uval at rz.uni-karlsruhe.de
Fri Feb 10 21:31:10 EST 2006
> 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
>>> dir(a)
['__copy__', '__deepcopy__', 'astype', 'byteswapped', 'copy',
'iscontiguous', 'itemsize', 'resize', 'savespace', 'spacesaver',
'tolist', 'toscalar', 'tostring', 'typecode']
>>> dir(nums)
['__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
More information about the Python-list
mailing list