I need to evaluate eigenvalues of a matrix which contains variables (see simplified code below). The function "test" enters other functions later and in the end I want to evaluate the function over a grid.
So far I am doing it with np.vectorize and nested for
loops (very slow) and want to increase the evaluation speed by using the numpy.meshgrid on the functions. However, the only thing I receive is the error message
Traceback (most recent call last):
File "test.py", line 8, in <module>
print(test(xx,yy))
File "test.py", line 4, in test
return np.linalg.eig(np.array([[1,x],[2,y]]))
ValueError: setting an array element with a sequence.
I read through the thread
but did not understand how I can apply the solutions presented there to my problem.
import numpy as np
def test(x,y):
return np.linalg.eig(np.array([[1,x],[2,y]]))
xx,yy =np.meshgrid(np.linspace(0,1,5),np.linspace(0,1,5),sparse=True)
print(test(xx,yy))