Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Or you could try numpy which is roughly 50 times faster

import time
import numpy as np
a=QQ(-1)

elapsed_time=0
for i in range(100):
    start=time.time()
    test = a*np.ones([1000,1000])
    end=time.time()
    elapsed_time=elapsed_time+(end-start)

print(elapsed_time/100)

But keep in mind that the example

from itertools import repeat
matrix(QQ,1000,1000,repeat(a,1000000))

generates a different type than a numpy array does

type(matrix(QQ,1000,1000,repeat(a,1000000)))
<type 'sage.matrix.matrix_rational_dense.Matrix_rational_dense'>

type(a*np.ones([1000,1000]))
<type 'numpy.ndarray'>