On Oct 23, 12:20 pm, Simon King <simon.k...@nuigalway.ie> wrote: > Hi! > > On 23 Okt., 11:59, Simon King <simon.k...@nuigalway.ie> wrote: > > > So, one should create an empty matrix and then insert the elements row > > by row. > > It it also more efficient on a smaller skale (and does the right > thing): > > sage: MS = MatrixSpace(ZZ,100,50) > sage: L = [[ZZ.random_element() for _ in range(50)] for __ in > range(100)] > sage: timeit('M = MS(0)\nfor i in range(len(L)): M[i]=L[i]') > 625 loops, best of 3: 602 µs per loop > sage: timeit('M = Matrix(ZZ,L)') > 125 loops, best of 3: 2.81 ms per loop > sage: M = MS(0) > sage: for i in range(len(L)): M[i]=L[i] > ....: > sage: M == Matrix(ZZ,L) > True > > Cheers, > Simon
In the matrix constructor (matrix in sage/matrix/constructor.py): entries = sum([list(v) for v in args[0]], []) <--- this is bad (quadratic in the length of argv[0] which is the number of rows here) Yann -- 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