[SciPy-User] Is there anything like polyval2?
josef.pktd at gmail.com
josef.pktd at gmail.com
Fri May 6 12:32:14 EDT 2011
On Fri, May 6, 2011 at 11:56 AM, Joseph Smidt <josephsmidt at gmail.com> wrote:
> Hi,
>
> Matlab has a function called polyval2 that evaluates a 2D
> polynomial from a a least-squares fit of 2D data:
> http://www.mathworks.com/matlabcentral/fx_files/13719/1/content/polyfitweighted2/publishpolyfitweighted2.html
>
> Does numpy or scipy have anything like this? Can it be done with
> existing routines in a straight forward way? I only see poly1d for
> one-dimensional polynomials.
I have written something like this several times (I often limit the
cross product to a simplex)
>>> nobs = 100
>>> x1 = np.random.randn(nobs)
>>> x2 = np.random.randn(nobs)
generate polynomial like a 2d np.vander:
>>> design = (x1[:,None, None]**np.arange(3)[None,:,None] * x2[:,None, None]**np.arange(3)[None,None,:]).reshape(nobs,-1)
>>> y = design.sum(1) + np.random.randn(nobs)
>>> params = np.linalg.lstsq(design, y)[0]
>>> predicted = np.dot(design, params)
Josef
>
> Thanks.
>
> --
> ------------------------------------------------------------------------
> Joseph Smidt <josephsmidt at gmail.com>
>
> Physics and Astronomy
> 2165 Frederick Reines Hall
> Irvine, CA 92697-4575
> Office: 949-824-9025
> _______________________________________________
> SciPy-User mailing list
> SciPy-User at scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
>
More information about the SciPy-User
mailing list