""" ___ """ from scipy.optimize import minimize import numpy as np LENGTH = 100 def process(x): return x * 2 + 5 def draw(process, length): """ """ y = np.random.normal(0, 10, length) data = [process(y_) for y_ in y] rnd = np.random.normal(3, 1, len(data)) return y, rnd + data def maximum_likelyhood(y, X): objective = lambda b: np.transpose(X) * (y - X * b) x0 = np.zeros(100) res = minimize(objective, x0=x0) return res.x y, X = draw(process, LENGTH) print maximum_likelyhood(y, X)
produces a
ValueError: setting an array element with a sequence.
There is several similar problems, they all point out that x0 is not a 1D array, but here it is a 1D array. (or not? in case please explain why and how to make it 1D)