Can I use lambda function with numpy's eig function?
Test problem:
import numpy as np
class c1:
def __init__(self):
self.mat1 = lambda num1:np.array([[num1,2],[3,4]])
self.mat2 = np.array([[1,2],[3,4]])
self.eigVal, self.eigVec = lambda num1:np.linalg.eig(self.mat2+self.mat1(num1))
def func1(self):
print(self.mat1(10))
print(self.eigVal(10))
c1().func1()
Error is TypeError: cannot unpack non-iterable function object.
lambdais a single function, and when you call it a single array that contains two arrays is produced. You cannot unpack that directly in the class, but you can do something likeself.eigFunc = lambda num1: np.linalg.eig(self.mat2 + self.mat1(num1))and unpack the results latereigval, eigvec = self.eigFunc(10)lambdawhen called can return 2 values, but the lambda itself is one object.lambdaafter I get error from the code below.self.eigFunc = lambda num1: np.linalg.eig(self.mat1(num1)); self.eigenVal = lambda num1 : self.eigFunc(num1)