Function returns a vector, how to minimize in via NumPy
问题 I'm trying to minimize function, that returns a vector of values, and here is an error: setting an array element with a sequence Code: P = np.matrix([[0.3, 0.1, 0.2], [0.01, 0.4, 0.2], [0.0001, 0.3, 0.5]]) Ps = np.array([10,14,5]) def objective(x): x = np.array([x]) res = np.square(Ps - np.dot(x, P)) return res def main(): x = np.array([10, 11, 15]) print minimize(objective, x, method='Nelder-Mead') At these values of P, Ps, x function returns [[ 47.45143225 16.81 44.89 ]] Thank you for any