# [SciPy-user] Fitting with global parameters optimize.leastsq

Steve Schmerler elcorto at gmx.net
Wed Nov 8 11:25:31 CST 2006

```Iain Day wrote:
>
> what is the difference between (length,) and (length,1)?
>

# numpy 1D array

In [31]: numpy.random.randn(5)
Out[31]: array([-1.56082001,  0.60259947, -1.54174779, -1.0866519 ,
0.82230522])

# Matlab-style 1D-arrays

# column vector (Nx1)

In [32]: numpy.random.randn(5,1)
Out[32]:
array([[ 1.36237411],
[ 0.34596444],
[ 1.0227412 ],
[-0.9647568 ],
[ 0.18561302]])

# row vector (1xN)

In [33]: numpy.random.randn(1,5)
Out[33]: array([[-0.82907498,  0.00139096, -0.34764322, -0.4300095 ,
0.61331211]])

>> 2) You're trying to fit all data sets (t == data_points, y ==
>> raw_signals[:, i]) at once and I guess that won't work. You have to loop
>> over A (or C or raw_signals[:, i]) building one data set and one initial
>> guess (x0 = numpy.array([A[i], B, C[i]])) per loop.
>
> That sounds similar to fitting each trace separately, and wouldn't give
> you the global B?
>

Well, yes. Taking a closer look at the cookbook example I see that this
is indeed the right thing to do :)

Although, I'm curious as to how this works if you don't fit 2 data sets
but, say 100 with respect to local mimima in a such a high-dimensional
search space.

--
cheers,
steve

Random number generation is the art of producing pure gibberish as
quickly as possible.
```