2d lists

beliavsky_at_aol.com
Date: 05/31/04


Date: 30 May 2004 16:44:03 -0700

xiaohua_sun@yahoo.com (SunX) wrote in message news:<337e6cd5.0405291411.4376debc@posting.google.com>...
> 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.

(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



Relevant Pages

  • Re: infinity
    ... from that two different infinite expansions in the same base can ... infinite lists are easily constructible in design ... only one sequence with all zeros, and only one sequence with all ones. ... For having one or more zeros with one or more ones there are infinitely ...
    (sci.math)
  • Formula to eliminate zeros
    ... I have a column of values that is 200 rows tall. ... concise list without 175 to 200 zeros. ... not have to filter the numerous lists with each job with a drop down ... the five digit option numbers to appear at the top of the list. ...
    (microsoft.public.excel.misc)
  • Macro to sort values in list without 0s (zeros)
    ... I have a some lists where I have made a macro so the user can choose to ... the bottom of the list. ... So my list has zeros in it, and I want it sorted A-Z, if i do this is ...
    (microsoft.public.excel.programming)
  • finding a list of numbers in a vector
    ... I have a 16-element long vector of ones and zeros. ... consists of two lists of 6 ones, one touching the start and one ... If 12 boys make a chain within that circle of 16 people, ...
    (comp.soft-sys.matlab)
  • Re: how to break a for loop?
    ... I would also use lists to implement this. ... that's why I encountered stupid problem: I need to remove zeros from ... Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org ...
    (comp.lang.python)