0

I get the following error with the function scipy.optimize.fsolve:

ValueError: operands could not be broadcast together with shapes (2,) (100,100)

the command is the following:

q = lambda alpha : np.mean(np.divide(alpha*np.identity(n)+(1-alpha)*matrix, matrix)-1) root = scipy.optimize.fsolve(lambda alpha: q(alpha)-0.3, [0, 1])

where n =100 and matrix is a symmetric 100x100 matrix.

The function q can be normally evaluted (e.g. q(0.4), q(0.5) etc. does not give any error), but I cannot apply the method fsolve.

userLx
  • 81
  • 8
  • Show the full error - with traceback. You/we need to identify exactly where the error occurs. If it is in `q`, you should display the type/dtype/shape of `alpha`. It may also help to rewrite as a normal function, and split the long calculation in several lines to better identify which arrays don't match. In other words - do the normal divide-n-conquer approach to debugging. – hpaulj Nov 17 '22 at 23:59

0 Answers0