1 | initial version |
Numpy arrays admit elementwise operations. So you could convert the matrix to a Numpy array, compute the new matriz R and then come back to a SageMath matrix:
R = D.numpy()
R = numpy.diff(R, axis=0)/R[0:-1,:]
R = matrix(R)
You can also opt for a pure Python approach:
nr, nc = D.nrows()-1, D.ncols()
R = matrix(nr, nc, [(D[i+1,j]-D[i,j])/D[i,j]
for i in range(nr) for j in range(nc)])
2 | No.2 Revision |
Numpy arrays admit elementwise operations. So you could convert the matrix to a Numpy array, compute the new matriz R and then come back to a SageMath matrix:
R = D.numpy()
R = numpy.diff(R, axis=0)/R[0:-1,:]
R = matrix(R)
You can also opt for a pure Python approach:
nr, nc = D.nrows()-1, D.ncols()
R = matrix(nr, nc, [(D[i+1,j]-D[i,j])/D[i,j]
for i in range(nr) for j in range(nc)])
The first method is faster.
3 | No.3 Revision |
Numpy arrays admit elementwise operations. So you could convert the matrix to a Numpy array, compute the new matriz R and then come back to a SageMath matrix:
import numpy
R = D.numpy()
R = numpy.diff(R, axis=0)/R[0:-1,:]
R = matrix(R)
You can also opt for a pure Python approach:
nr, nc = D.nrows()-1, D.ncols()
R = matrix(nr, nc, [(D[i+1,j]-D[i,j])/D[i,j]
for i in range(nr) for j in range(nc)])
The first method is faster.
4 | No.4 Revision |
Numpy arrays admit elementwise operations. So you could convert the matrix to a Numpy array, compute the new matriz matrix R and then come back to a SageMath matrix:
import numpy
R = D.numpy()
R = numpy.diff(R, axis=0)/R[0:-1,:]
R = matrix(R)
You can also opt for a pure Python approach:
nr, nc = D.nrows()-1, D.ncols()
R = matrix(nr, nc, [(D[i+1,j]-D[i,j])/D[i,j]
for i in range(nr) for j in range(nc)])
The first method is faster.