![](https://secure.gravatar.com/avatar/afdaaab755ef79ac9e1374882d60ae9f.jpg?s=120&d=mm&r=g)
April 24, 2008
5:57 p.m.
norm = 1 / (scale * sqrt(2 * pi)) y = norm * exp(-power((x - loc), 2) / (2 * scale**2))
Hmm-m-m. I don't understand the source of the error:
y = norm * exp(-pow((x - loc), 2) / (2 * scale**2)) TypeError: only length-1 arrays can be converted to Python scalars
Python's built in pow() and exp() functions can't handle numpy arrays, and thus try (and fail) to convert arrays to scalar values. You want to use numpy.exp and numpy.power (or just the ** operator), to do these operations to numpy arrays elementwise.