# Revision history [back]

Alternatively, the matrix constructor can get an explicit list of lists (or the flat list associated to this one), instead of a function, and there is no confusion any longer. (Well, also using i will overwrite the default value of this variable in sage, which corresponds to $\sqrt{-1}$, i will use k and n instead of i, j .)

For instance:

sage: [ 1/(k+n) for k in [1..3] for n in [1..3] ]
[1/2, 1/3, 1/4, 1/3, 1/4, 1/5, 1/4, 1/5, 1/6]
sage: [ [ 1/(k+n) for k in [1..3] ] for n in [1..3] ]
[[1/2, 1/3, 1/4], [1/3, 1/4, 1/5], [1/4, 1/5, 1/6]]

sage: matrix( QQ, [ 1/(k+n) for k in [1..3] for n in [1..3] ] )    # bad
[1/2 1/3 1/4 1/3 1/4 1/5 1/4 1/5 1/6]

sage: matrix( QQ, 3, [ 1/(k+n) for k in [1..3] for n in [1..3] ] )
[1/2 1/3 1/4]
[1/3 1/4 1/5]
[1/4 1/5 1/6]
sage: matrix( QQ, 3, 3, [ 1/(k+n) for k in [1..3] for n in [1..3] ] )
[1/2 1/3 1/4]
[1/3 1/4 1/5]
[1/4 1/5 1/6]

sage: matrix( QQ, [ [ 1/(k+n) for k in [1..3] ] for n in [1..3] ] )
[1/2 1/3 1/4]
[1/3 1/4 1/5]
[1/4 1/5 1/6]
sage: matrix( QQ, 3, [ [ 1/(k+n) for k in [1..3] ] for n in [1..3] ] )
[1/2 1/3 1/4]
[1/3 1/4 1/5]
[1/4 1/5 1/6]
sage: matrix( QQ, 3, 3, [ [ 1/(k+n) for k in [1..3] ] for n in [1..3] ] )
[1/2 1/3 1/4]
[1/3 1/4 1/5]
[1/4 1/5 1/6]