Here is another way:

sage: coeffs = [[i^2-j for j in range(6)] for i in range(6)]
sage: matrix(coeffs)
[ 0 -1 -2 -3 -4 -5]
[ 1  0 -1 -2 -3 -4]
[ 4  3  2  1  0 -1]
[ 9  8  7  6  5  4]
[16 15 14 13 12 11]
[25 24 23 22 21 20]


On Sat, Mar 13, 2010 at 7:58 AM, Alasdair <amc...@gmail.com> wrote:
> This can be done in maxima:
>
> genmatrix(lambda([i,j],i-j),6,6);
>
> for example.  But is there an easy Sage way of doing this?  If I enter
>
> sage: M=maxima('genmatrix(lambda([i,j],i-j),6,6)')
>
> then I obtain a Maxima matrix, which then has to turned into a Sage
> matrix (I don't know how to do this either).  Clearly I could:
>
> sage: M=matrix(ZZ,6,6)
> sage: for i in range(6):
> ....:     for j in range(6):
> ....:         M[i,j]=i-j
>
> but that seems a bit longwinded.  Is there an easy straightforward
> way?
>
> Thanks,
> Alasdair
>
> --
> To post to this group, send email to sage-support@googlegroups.com
> To unsubscribe from this group, send email to 
> sage-support+unsubscr...@googlegroups.com
> For more options, visit this group at 
> http://groups.google.com/group/sage-support
> URL: http://www.sagemath.org
>

-- 
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org

Reply via email to