Thanks to visit codestin.com
Credit goes to github.com

Skip to content

ENH: polyvalnd, N-dimensional polynomial evaluation #30857

@lpsinger

Description

@lpsinger

Proposed new feature or change:

I have a need for a function polyvalnd which is just like polyval, polyval2d, or polyval3d, but that handles arbitrary dimensions. Surprisingly this function does not already exist in Numpy. It is trivial to implement with existing non-public utilities in Numpy, i.e.,

from numpy.polynomial import polyutils as pu
from numpy.polynomial.polynomial import polyval


def polyvalnd(x, c):
    """Evaluate an arbitrary multivariate polynomial."""
    return pu._valnd(polyval, c, *x)

Of course there is a decision to make about the signature, because with polyval2d and polyval3d the arguments are passed like this:

polyval2d(x, y, c)
polyval3d(x, y, c)

So we would have to decide which of these we prefer:

polyvalnd(p, q, ..., x, y, z, c)  # ordinates first
polyvalnd(c, p, q, ..., x, y, z)  # ordinates last
polyvalnd([p, q, ..., x, y, z], c)  # ordinates first, in an list

This has been suggested before in #6071, but my needs are much narrower: I don't need N-D Chebyshev polynomials, etc.

My application is that I need some multivariate polynomial test data for a multivariate interpolation scheme that I am working on with a student.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions