On Mar 14, 6:15 pm, Alec Mihailovs <alec.mihail...@gmail.com> wrote: > That could be also done as > > from numpy import fromfunction > > matrix(fromfunction(lambda i,j:i-j, (6,6), dtype=int)) > > [ 0 -1 -2 -3 -4 -5] > [ 1 0 -1 -2 -3 -4] > [ 2 1 0 -1 -2 -3] > [ 3 2 1 0 -1 -2] > [ 4 3 2 1 0 -1] > [ 5 4 3 2 1 0]
However, testing that, I found 2 problems. First, dtype=int works not very well for integers greater than 2^31-1. For example, matrix(fromfunction(lambda i,j:(i+j)^31, (2,2), dtype=int)) [ 0 1] [ 1 -2147483648] That can be fixed by using dtype=object instead. matrix(fromfunction(lambda i,j:(i+j)^65, (2,2), dtype=object)) [ 0 1] [ 1 36893488147419103232] The second problem is that something strange happens for 1x1 matrices, with any dtype, matrix(fromfunction(lambda i,j:i-j,(1,1),dtype=int)) [] matrix(fromfunction(lambda i,j:i-j+3,(1,1),dtype=int)) [0 0 0] [0 0 0] [0 0 0] Alec Mihailovs -- 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