# Revision history [back]

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)])


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.

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.

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.