newbie : array initialization, anyone ?
Curtis Jensen
cjensen at bioeng.ucsd.edu
Wed Dec 27 14:36:10 EST 2000
Gerson Kurz wrote:
>
> you can initialize a fixed-size array using something like
>
> array = [0] * 10
>
> now, one would think that you can initialize a multidimensional array
> like this:
>
> multidim = [ [0] * 10 ] * 3
>
> but now, all 3 elements in multidim are references to the same single
> array, so that if you type
>
> multidim[0][0] = 1
> print multidim
>
> you actually get three 1 in all those 0s. Where did my thinking go
> wrong along these lines ?
If you use NumPy (http://sourceforge.net/projects/numpy/) you can do:
array = zeros([10]) or
array = ones([10]) if you want initualized to ones.
--
Curtis Jensen
cjensen at bioeng.ucsd.edu
http://www-bioeng.ucsd.edu/~cjensen/
FAX (425) 740-1451
More information about the Python-list
mailing list