Ask Your Question

Revision history [back]

You can use numpy to compute the covariance of two list of numbers:

sage: x = [random() for _ in range(10)]
sage: y = [random() for _ in range(10)]
sage: np.cov(x,y)
array([[ 0.09306006, -0.04053014],
       [-0.04053014,  0.10647864]])

The numpy array can be converted back into a SageMath matrix:

sage: matrix(_)
[ 0.09306006427535807 -0.04053014267978353]
[-0.04053014267978353  0.10647864456311205]

More usage examples can be found in the numpy doc.

You can use numpy to compute the covariance of two list of numbers:

sage: x = [random() for _ in range(10)]
sage: y = [random() for _ in range(10)]
sage: import numpy as np
sage: np.cov(x,y)
array([[ 0.09306006, -0.04053014],
       [-0.04053014,  0.10647864]])

The numpy array can be converted back into a SageMath matrix:

sage: matrix(_)
[ 0.09306006427535807 -0.04053014267978353]
[-0.04053014267978353  0.10647864456311205]

More usage examples can be found in the numpy doc.