xiaohua_sun@yah oo.com (SunX) wrote in message news:<337e6cd5. 0405291411.4376 debc@posting.go ogle.com>...[color=blue]
> What is the best way to assign a 2d lists? Something like;
>
> for i in range(10):
> for j in range(10):
> aList[i][j] = i*j
>
> Thank you in advance.[/color]
(When I replied with subject "Re: 2d lists" Google groups complained.)
If you will use the 2d lists for numerical calculations, I would
recommend the Numeric or Numarray modules, which provide
multdimensional arrays that are much faster than lists of lists. A
restriction of Numeric or Numarray arrays is that all the elements
must be of the same type (as in Fortran).
With Numeric you could write
from Numeric import zeros
n = 10
alist = zeros([n,n])
for i in range(n):
for j in range(n):
alist[i,j] = i*j
> What is the best way to assign a 2d lists? Something like;
>
> for i in range(10):
> for j in range(10):
> aList[i][j] = i*j
>
> Thank you in advance.[/color]
(When I replied with subject "Re: 2d lists" Google groups complained.)
If you will use the 2d lists for numerical calculations, I would
recommend the Numeric or Numarray modules, which provide
multdimensional arrays that are much faster than lists of lists. A
restriction of Numeric or Numarray arrays is that all the elements
must be of the same type (as in Fortran).
With Numeric you could write
from Numeric import zeros
n = 10
alist = zeros([n,n])
for i in range(n):
for j in range(n):
alist[i,j] = i*j