I am sure that I am missing something here, I have some larger matrices and Mathematica takes too long to compute the eigenvalues and vectors (using Eigensystem[m]
) so I would like to pass them to a python environment using ExternalEvaluate
so as to take advantage of Python's much faster computation for this.
I am sure there is an easy way to pass my matrix to Python, but I cannot see how.
MWE:
In[1]:= linearMap = {{1, 0, 0, 0, 0, 0, 0}, {0, 1, 0, 0, 0, 0, 0}, {0, 0, 1, 0, 0, 0, 0},
{0, 0, 0, 1/4, 0, 0, 0}, {0, 0, 0, 0, 1/2, 0, 0},
{0, 0, 0, 0, 0, 1/2, 0}, {0, 0, 0, 0, 0, 0, 1/4}};
In[2]:= ExternalEvaluate["Python", "import numpy; numpy.linalg.eigvalsh(linearMap)"]
Out[2]=
I am very aware that it is not necessary for such small matrices (or indeed this matrix at all really!), but as they get larger, I would greatly appreciate the ability to utilise the speed increases.
Clearly this isn't expected to work instantly as the linearMap
from Mathematica would need to be reformatted to a Python array. I am just hoping that there is an easy way to do this that I have overlooked...
Eigensystem
, as in yourlinearMap
example. If so, useEigensystem[N@linearMap]
instead. $\endgroup$