<EOL>[c1, c2] = pu.as_series([c1, c2])<EOL>if len(c1) > len(c2):<EOL><INDENT>c = c2<EOL>xs = c1<EOL><DEDENT>else:<EOL><INDENT>c = c1<EOL>xs = c2<EOL><DEDENT>if len(c) == <NUM_LIT:1>:<EOL><INDENT>c0 = c[<NUM_LIT:0>]*xs<EOL>c1 = <NUM_LIT:0><EOL><DEDENT>elif len(c) == <NUM_LIT:2>:<EOL><INDENT>c0 = c[<NUM_LIT:0>]*xs<EOL>c1 = c[<NUM_LIT:1>]*xs<EOL><DEDENT>else:<EOL><INDENT>nd = len(c)<EOL>c0 = c[-<NUM_LIT:2>]*xs<EOL>c1 = c[-<NUM_LIT:1>]*xs<EOL>for i in range(<NUM_LIT:3>, len(c) + <NUM_LIT:1>):<EOL><INDENT>tmp = c0<EOL>nd = nd - <NUM_LIT:1><EOL>c0 = legsub(c[-i]*xs, (c1*(nd - <NUM_LIT:1>))/nd)<EOL>c1 = legadd(tmp, (legmulx(c1)*(<NUM_LIT:2>*nd - <NUM_LIT:1>))/nd)<EOL><DEDENT><DEDENT>return legadd(c0, legmulx(c1))<EOL>

Multiply one Legendre series by another.

Returns the product of two Legendre series `c1` * `c2`.  The arguments
are sequences of coefficients, from lowest order "term" to highest,
e.g., [1,2,3] represents the series ``P_0 + 2*P_1 + 3*P_2``.

Parameters
----------
c1, c2 : array_like
    1-D arrays of Legendre series coefficients ordered from low to
    high.

Returns
-------
out : ndarray
    Of Legendre series coefficients representing their product.

See Also
--------
legadd, legsub, legdiv, legpow

Notes
-----
In general, the (polynomial) product of two C-series results in terms
that are not in the Legendre polynomial basis set.  Thus, to express
the product as a Legendre series, it is necessary to "reproject" the
product onto said basis set, which may produce "unintuitive" (but
correct) results; see Examples section below.

Examples
--------
>>> from numpy.polynomial import legendre as L
>>> c1 = (1,2,3)
>>> c2 = (3,2)
>>> P.legmul(c1,c2) # multiplication requires "reprojection"
array([  4.33333333,  10.4       ,  11.66666667,   3.6       ])


w = x*<NUM_LIT:0.0> + <NUM_LIT:1.0><EOL>return w<EOL>

Weight function of the Legendre polynomials.

The weight function is :math:`1` and the interval of integration is
:math:`[-1, 1]`. The Legendre polynomials are orthogonal, but not
normalized, with respect to this weight function.

Parameters
----------
x : array_like
   Values at which the weight function will be computed.

Returns
-------
w : ndarray
   The weight function at `x`.

Notes
-----

.. versionadded::1.7.0


ideg = [int(d) for d in deg]<EOL>is_valid = [id == d and id >= <NUM_LIT:0> for id, d in zip(ideg, deg)]<EOL>if is_valid != [<NUM_LIT:1>, <NUM_LIT:1>, <NUM_LIT:1>]:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>degx, degy, degz = ideg<EOL>x, y, z = np.array((x, y, z), copy=<NUM_LIT:0>) + <NUM_LIT:0.0><EOL>vx = legvander(x, degx)<EOL>vy = legvander(y, degy)<EOL>vz = legvander(z, degz)<EOL>v = vx[..., None, None]*vy[..., None,:, None]*vz[..., None, None,:]<EOL>return v.reshape(v.shape[:-<NUM_LIT:3>] + (-<NUM_LIT:1>,))<EOL>

Pseudo-Vandermonde matrix of given degrees.

    Returns the pseudo-Vandermonde matrix of degrees `deg` and sample
    points `(x, y, z)`. If `l, m, n` are the given degrees in `x, y, z`,
    then The pseudo-Vandermonde matrix is defined by

    .. math:: V[..., (m+1)(n+1)i + (n+1)j + k] = L_i(x)*L_j(y)*L_k(z),

    where `0 <= i <= l`, `0 <= j <= m`, and `0 <= j <= n`.  The leading
    indices of `V` index the points `(x, y, z)` and the last index encodes
    the degrees of the Legendre polynomials.

    If ``V = legvander3d(x, y, z, [xdeg, ydeg, zdeg])``, then the columns
    of `V` correspond to the elements of a 3-D coefficient array `c` of
    shape (xdeg + 1, ydeg + 1, zdeg + 1) in the order

    .. math:: c_{000}, c_{001}, c_{002},... , c_{010}, c_{011}, c_{012},...

    and ``np.dot(V, c.flat)`` and ``legval3d(x, y, z, c)`` will be the
    same up to roundoff. This equivalence is useful both for least squares
    fitting and for the evaluation of a large number of 3-D Legendre
    series of the same degrees and sample points.

    Parameters
    ----------
    x, y, z : array_like
        Arrays of point coordinates, all of the same shape. The dtypes will
        be converted to either float64 or complex128 depending on whether
        any of the elements are complex. Scalars are converted to 1-D
        arrays.
    deg : list of ints
        List of maximum degrees of the form [x_deg, y_deg, z_deg].

    Returns
    -------
    vander3d : ndarray
        The shape of the returned matrix is ``x.shape + (order,)``, where
        :math:`order = (deg[0]+1)*(deg([1]+1)*(deg[2]+1)`.  The dtype will
        be the same as the converted `x`, `y`, and `z`.

    See Also
    --------
    legvander, legvander3d. legval2d, legval3d

    Notes
    -----

    .. versionadded::1.7.0


def legder(c, m=<NUM_LIT:1>, scl=<NUM_LIT:1>, axis=<NUM_LIT:0>):

c = np.array(c, ndmin=<NUM_LIT:1>, copy=<NUM_LIT:1>)<EOL>if c.dtype.char in '<STR_LIT>':<EOL><INDENT>c = c.astype(np.double)<EOL><DEDENT>cnt, iaxis = [int(t) for t in [m, axis]]<EOL>if cnt != m:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if cnt < <NUM_LIT:0>:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if iaxis != axis:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if not -c.ndim <= iaxis < c.ndim:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if iaxis < <NUM_LIT:0>:<EOL><INDENT>iaxis += c.ndim<EOL><DEDENT>if cnt == <NUM_LIT:0>:<EOL><INDENT>return c<EOL><DEDENT>c = np.rollaxis(c, iaxis)<EOL>n = len(c)<EOL>if cnt >= n:<EOL><INDENT>c = c[:<NUM_LIT:1>]*<NUM_LIT:0><EOL><DEDENT>else:<EOL><INDENT>for i in range(cnt):<EOL><INDENT>n = n - <NUM_LIT:1><EOL>c *= scl<EOL>der = np.empty((n,) + c.shape[<NUM_LIT:1>:], dtype=c.dtype)<EOL>for j in range(n, <NUM_LIT:2>, -<NUM_LIT:1>):<EOL><INDENT>der[j - <NUM_LIT:1>] = (<NUM_LIT:2>*j - <NUM_LIT:1>)*c[j]<EOL>c[j - <NUM_LIT:2>] += c[j]<EOL><DEDENT>if n > <NUM_LIT:1>:<EOL><INDENT>der[<NUM_LIT:1>] = <NUM_LIT:3>*c[<NUM_LIT:2>]<EOL><DEDENT>der[<NUM_LIT:0>] = c[<NUM_LIT:1>]<EOL>c = der<EOL><DEDENT><DEDENT>c = np.rollaxis(c, <NUM_LIT:0>, iaxis + <NUM_LIT:1>)<EOL>return c<EOL>

Differentiate a Legendre series.

Returns the Legendre series coefficients `c` differentiated `m` times
along `axis`.  At each iteration the result is multiplied by `scl` (the
scaling factor is for use in a linear change of variable). The argument
`c` is an array of coefficients from low to high degree along each
axis, e.g., [1,2,3] represents the series ``1*L_0 + 2*L_1 + 3*L_2``
while [[1,2],[1,2]] represents ``1*L_0(x)*L_0(y) + 1*L_1(x)*L_0(y) +
2*L_0(x)*L_1(y) + 2*L_1(x)*L_1(y)`` if axis=0 is ``x`` and axis=1 is
``y``.

Parameters
----------
c : array_like
    Array of Legendre series coefficients. If c is multidimensional the
    different axis correspond to different variables with the degree in
    each axis given by the corresponding index.
m : int, optional
    Number of derivatives taken, must be non-negative. (Default: 1)
scl : scalar, optional
    Each differentiation is multiplied by `scl`.  The end result is
    multiplication by ``scl**m``.  This is for use in a linear change of
    variable. (Default: 1)
axis : int, optional
    Axis over which the derivative is taken. (Default: 0).

    .. versionadded:: 1.7.0

Returns
-------
der : ndarray
    Legendre series of the derivative.

See Also
--------
legint

Notes
-----
In general, the result of differentiating a Legendre series does not
resemble the same operation on a power series. Thus the result of this
function may be "unintuitive," albeit correct; see Examples section
below.

Examples
--------
>>> from numpy.polynomial import legendre as L
>>> c = (1,2,3,4)
>>> L.legder(c)
array([  6.,   9.,  20.])
>>> L.legder(c, 3)
array([ 60.])
>>> L.legder(c, scl=-1)
array([ -6.,  -9., -20.])
>>> L.legder(c, 2,-1)
array([  9.,  60.])


c = polyval(x, c)<EOL>c = polyval(y, c)<EOL>c = polyval(z, c)<EOL>return c<EOL>

Evaluate a 3-D polynomial on the Cartesian product of x, y and z.

This function returns the values:

.. math:: p(a,b,c) = \\sum_{i,j,k} c_{i,j,k} * a^i * b^j * c^k

where the points `(a, b, c)` consist of all triples formed by taking
`a` from `x`, `b` from `y`, and `c` from `z`. The resulting points form
a grid with `x` in the first dimension, `y` in the second, and `z` in
the third.

The parameters `x`, `y`, and `z` are converted to arrays only if they
are tuples or a lists, otherwise they are treated as a scalars. In
either case, either `x`, `y`, and `z` or their elements must support
multiplication and addition both with themselves and with the elements
of `c`.

If `c` has fewer than three dimensions, ones are implicitly appended to
its shape to make it 3-D. The shape of the result will be c.shape[3:] +
x.shape + y.shape + z.shape.

Parameters
----------
x, y, z : array_like, compatible objects
    The three dimensional series is evaluated at the points in the
    Cartesian product of `x`, `y`, and `z`.  If `x`,`y`, or `z` is a
    list or tuple, it is first converted to an ndarray, otherwise it is
    left unchanged and, if it isn't an ndarray, it is treated as a
    scalar.
c : array_like
    Array of coefficients ordered so that the coefficients for terms of
    degree i,j are contained in ``c[i,j]``. If `c` has dimension
    greater than two the remaining indices enumerate multiple sets of
    coefficients.

Returns
-------
values : ndarray, compatible object
    The values of the two dimensional polynomial at points in the Cartesian
    product of `x` and `y`.

See Also
--------
polyval, polyval2d, polygrid2d, polyval3d

Notes
-----

.. versionadded:: 1.7.0


<EOL>[c] = pu.as_series([c])<EOL>if len(c) == <NUM_LIT:1> and c[<NUM_LIT:0>] == <NUM_LIT:0>:<EOL><INDENT>return c<EOL><DEDENT>prd = np.empty(len(c) + <NUM_LIT:1>, dtype=c.dtype)<EOL>prd[<NUM_LIT:0>] = c[<NUM_LIT:0>]*<NUM_LIT:0><EOL>prd[<NUM_LIT:1>:] = c<EOL>return prd<EOL>

Multiply a polynomial by x.

    Multiply the polynomial `c` by x, where x is the independent
    variable.

    Parameters
    ----------
    c : array_like
        1-D array of polynomial coefficients ordered from low to
        high.

    Returns
    -------
    out : ndarray
        Array representing the result of the multiplication.

    Notes
    -----

    .. versionadded:: 1.5.0


<EOL>[c] = pu.as_series([c])<EOL>if len(c) < <NUM_LIT:2>:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>if len(c) == <NUM_LIT:2>:<EOL><INDENT>return np.array([[-c[<NUM_LIT:0>]/c[<NUM_LIT:1>]]])<EOL><DEDENT>n = len(c) - <NUM_LIT:1><EOL>mat = np.zeros((n, n), dtype=c.dtype)<EOL>bot = mat.reshape(-<NUM_LIT:1>)[n::n+<NUM_LIT:1>]<EOL>bot[...] = <NUM_LIT:1><EOL>mat[:, -<NUM_LIT:1>] -= c[:-<NUM_LIT:1>]/c[-<NUM_LIT:1>]<EOL>return mat<EOL>

Return the companion matrix of c.

The companion matrix for power series cannot be made symmetric by
scaling the basis, so this function differs from those for the
orthogonal polynomials.

Parameters
----------
c : array_like
    1-D array of polynomial coefficients ordered from low to high
    degree.

Returns
-------
mat : ndarray
    Companion matrix of dimensions (deg, deg).

Notes
-----

.. versionadded:: 1.7.0


<EOL>[c1, c2] = pu.as_series([c1, c2])<EOL>if len(c1) > len(c2):<EOL><INDENT>c1[:c2.size] += c2<EOL>ret = c1<EOL><DEDENT>else:<EOL><INDENT>c2[:c1.size] += c1<EOL>ret = c2<EOL><DEDENT>return pu.trimseq(ret)<EOL>

Add one polynomial to another.

Returns the sum of two polynomials `c1` + `c2`.  The arguments are
sequences of coefficients from lowest order term to highest, i.e.,
[1,2,3] represents the polynomial ``1 + 2*x + 3*x**2``.

Parameters
----------
c1, c2 : array_like
    1-D arrays of polynomial coefficients ordered from low to high.

Returns
-------
out : ndarray
    The coefficient array representing their sum.

See Also
--------
polysub, polymul, polydiv, polypow

Examples
--------
>>> from numpy.polynomial import polynomial as P
>>> c1 = (1,2,3)
>>> c2 = (3,2,1)
>>> sum = P.polyadd(c1,c2); sum
array([ 4.,  4.,  4.])
>>> P.polyval(2, sum) # 4 + 4(2) + 4(2**2)
28.0


try:<EOL><INDENT>x, y, z = np.array((x, y, z), copy=<NUM_LIT:0>)<EOL><DEDENT>except:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>c = polyval(x, c)<EOL>c = polyval(y, c, tensor=False)<EOL>c = polyval(z, c, tensor=False)<EOL>return c<EOL>

Evaluate a 3-D polynomial at points (x, y, z).

This function returns the values:

.. math:: p(x,y,z) = \\sum_{i,j,k} c_{i,j,k} * x^i * y^j * z^k

The parameters `x`, `y`, and `z` are converted to arrays only if
they are tuples or a lists, otherwise they are treated as a scalars and
they must have the same shape after conversion. In either case, either
`x`, `y`, and `z` or their elements must support multiplication and
addition both with themselves and with the elements of `c`.

If `c` has fewer than 3 dimensions, ones are implicitly appended to its
shape to make it 3-D. The shape of the result will be c.shape[3:] +
x.shape.

Parameters
----------
x, y, z : array_like, compatible object
    The three dimensional series is evaluated at the points
    `(x, y, z)`, where `x`, `y`, and `z` must have the same shape.  If
    any of `x`, `y`, or `z` is a list or tuple, it is first converted
    to an ndarray, otherwise it is left unchanged and if it isn't an
    ndarray it is  treated as a scalar.
c : array_like
    Array of coefficients ordered so that the coefficient of the term of
    multi-degree i,j,k is contained in ``c[i,j,k]``. If `c` has dimension
    greater than 3 the remaining indices enumerate multiple sets of
    coefficients.

Returns
-------
values : ndarray, compatible object
    The values of the multidimensional polynomial on points formed with
    triples of corresponding values from `x`, `y`, and `z`.

See Also
--------
polyval, polyval2d, polygrid2d, polygrid3d

Notes
-----

.. versionadded:: 1.7.0


<EOL>[c1, c2] = pu.as_series([c1, c2])<EOL>if len(c1) > len(c2):<EOL><INDENT>c1[:c2.size] -= c2<EOL>ret = c1<EOL><DEDENT>else:<EOL><INDENT>c2 = -c2<EOL>c2[:c1.size] += c1<EOL>ret = c2<EOL><DEDENT>return pu.trimseq(ret)<EOL>

Subtract one polynomial from another.

Returns the difference of two polynomials `c1` - `c2`.  The arguments
are sequences of coefficients from lowest order term to highest, i.e.,
[1,2,3] represents the polynomial ``1 + 2*x + 3*x**2``.

Parameters
----------
c1, c2 : array_like
    1-D arrays of polynomial coefficients ordered from low to
    high.

Returns
-------
out : ndarray
    Of coefficients representing their difference.

See Also
--------
polyadd, polymul, polydiv, polypow

Examples
--------
>>> from numpy.polynomial import polynomial as P
>>> c1 = (1,2,3)
>>> c2 = (3,2,1)
>>> P.polysub(c1,c2)
array([-2.,  0.,  2.])
>>> P.polysub(c2,c1) # -P.polysub(c1,c2)
array([ 2.,  0., -2.])


ideg = int(deg)<EOL>if ideg != deg:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if ideg < <NUM_LIT:0>:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>x = np.array(x, copy=<NUM_LIT:0>, ndmin=<NUM_LIT:1>) + <NUM_LIT:0.0><EOL>dims = (ideg + <NUM_LIT:1>,) + x.shape<EOL>dtyp = x.dtype<EOL>v = np.empty(dims, dtype=dtyp)<EOL>v[<NUM_LIT:0>] = x*<NUM_LIT:0> + <NUM_LIT:1><EOL>if ideg > <NUM_LIT:0>:<EOL><INDENT>v[<NUM_LIT:1>] = x<EOL>for i in range(<NUM_LIT:2>, ideg + <NUM_LIT:1>):<EOL><INDENT>v[i] = v[i-<NUM_LIT:1>]*x<EOL><DEDENT><DEDENT>return np.rollaxis(v, <NUM_LIT:0>, v.ndim)<EOL>

Vandermonde matrix of given degree.

    Returns the Vandermonde matrix of degree `deg` and sample points
    `x`. The Vandermonde matrix is defined by

    .. math:: V[..., i] = x^i,

    where `0 <= i <= deg`. The leading indices of `V` index the elements of
    `x` and the last index is the power of `x`.

    If `c` is a 1-D array of coefficients of length `n + 1` and `V` is the
    matrix ``V = polyvander(x, n)``, then ``np.dot(V, c)`` and
    ``polyval(x, c)`` are the same up to roundoff. This equivalence is
    useful both for least squares fitting and for the evaluation of a large
    number of polynomials of the same degree and sample points.

    Parameters
    ----------
    x : array_like
        Array of points. The dtype is converted to float64 or complex128
        depending on whether any of the elements are complex. If `x` is
        scalar it is converted to a 1-D array.
    deg : int
        Degree of the resulting matrix.

    Returns
    -------
    vander : ndarray.
        The Vandermonde matrix. The shape of the returned matrix is
        ``x.shape + (deg + 1,)``, where the last index is the power of `x`.
        The dtype will be the same as the converted `x`.

    See Also
    --------
    polyvander2d, polyvander3d


c = hermeval(x, c)<EOL>c = hermeval(y, c)<EOL>return c<EOL>

Evaluate a 2-D HermiteE series on the Cartesian product of x and y.

This function returns the values:

.. math:: p(a,b) = \sum_{i,j} c_{i,j} * H_i(a) * H_j(b)

where the points `(a, b)` consist of all pairs formed by taking
`a` from `x` and `b` from `y`. The resulting points form a grid with
`x` in the first dimension and `y` in the second.

The parameters `x` and `y` are converted to arrays only if they are
tuples or a lists, otherwise they are treated as a scalars. In either
case, either `x` and `y` or their elements must support multiplication
and addition both with themselves and with the elements of `c`.

If `c` has fewer than two dimensions, ones are implicitly appended to
its shape to make it 2-D. The shape of the result will be c.shape[2:] +
x.shape.

Parameters
----------
x, y : array_like, compatible objects
    The two dimensional series is evaluated at the points in the
    Cartesian product of `x` and `y`.  If `x` or `y` is a list or
    tuple, it is first converted to an ndarray, otherwise it is left
    unchanged and, if it isn't an ndarray, it is treated as a scalar.
c : array_like
    Array of coefficients ordered so that the coefficients for terms of
    degree i,j are contained in ``c[i,j]``. If `c` has dimension
    greater than two the remaining indices enumerate multiple sets of
    coefficients.

Returns
-------
values : ndarray, compatible object
    The values of the two dimensional polynomial at points in the Cartesian
    product of `x` and `y`.

See Also
--------
hermeval, hermeval2d, hermeval3d, hermegrid3d

Notes
-----

.. versionadded::1.7.0


try:<EOL><INDENT>x, y, z = np.array((x, y, z), copy=<NUM_LIT:0>)<EOL><DEDENT>except:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>c = hermeval(x, c)<EOL>c = hermeval(y, c, tensor=False)<EOL>c = hermeval(z, c, tensor=False)<EOL>return c<EOL>

Evaluate a 3-D Hermite_e series at points (x, y, z).

This function returns the values:

.. math:: p(x,y,z) = \\sum_{i,j,k} c_{i,j,k} * He_i(x) * He_j(y) * He_k(z)

The parameters `x`, `y`, and `z` are converted to arrays only if
they are tuples or a lists, otherwise they are treated as a scalars and
they must have the same shape after conversion. In either case, either
`x`, `y`, and `z` or their elements must support multiplication and
addition both with themselves and with the elements of `c`.

If `c` has fewer than 3 dimensions, ones are implicitly appended to its
shape to make it 3-D. The shape of the result will be c.shape[3:] +
x.shape.

Parameters
----------
x, y, z : array_like, compatible object
    The three dimensional series is evaluated at the points
    `(x, y, z)`, where `x`, `y`, and `z` must have the same shape.  If
    any of `x`, `y`, or `z` is a list or tuple, it is first converted
    to an ndarray, otherwise it is left unchanged and if it isn't an
    ndarray it is  treated as a scalar.
c : array_like
    Array of coefficients ordered so that the coefficient of the term of
    multi-degree i,j,k is contained in ``c[i,j,k]``. If `c` has dimension
    greater than 3 the remaining indices enumerate multiple sets of
    coefficients.

Returns
-------
values : ndarray, compatible object
    The values of the multidimensional polynomial on points formed with
    triples of corresponding values from `x`, `y`, and `z`.

See Also
--------
hermeval, hermeval2d, hermegrid2d, hermegrid3d

Notes
-----

.. versionadded::1.7.0


<EOL>[c1, c2] = pu.as_series([c1, c2])<EOL>if len(c1) > len(c2):<EOL><INDENT>c = c2<EOL>xs = c1<EOL><DEDENT>else:<EOL><INDENT>c = c1<EOL>xs = c2<EOL><DEDENT>if len(c) == <NUM_LIT:1>:<EOL><INDENT>c0 = c[<NUM_LIT:0>]*xs<EOL>c1 = <NUM_LIT:0><EOL><DEDENT>elif len(c) == <NUM_LIT:2>:<EOL><INDENT>c0 = c[<NUM_LIT:0>]*xs<EOL>c1 = c[<NUM_LIT:1>]*xs<EOL><DEDENT>else:<EOL><INDENT>nd = len(c)<EOL>c0 = c[-<NUM_LIT:2>]*xs<EOL>c1 = c[-<NUM_LIT:1>]*xs<EOL>for i in range(<NUM_LIT:3>, len(c) + <NUM_LIT:1>):<EOL><INDENT>tmp = c0<EOL>nd = nd - <NUM_LIT:1><EOL>c0 = hermesub(c[-i]*xs, c1*(nd - <NUM_LIT:1>))<EOL>c1 = hermeadd(tmp, hermemulx(c1))<EOL><DEDENT><DEDENT>return hermeadd(c0, hermemulx(c1))<EOL>

Multiply one Hermite series by another.

Returns the product of two Hermite series `c1` * `c2`.  The arguments
are sequences of coefficients, from lowest order "term" to highest,
e.g., [1,2,3] represents the series ``P_0 + 2*P_1 + 3*P_2``.

Parameters
----------
c1, c2 : array_like
    1-D arrays of Hermite series coefficients ordered from low to
    high.

Returns
-------
out : ndarray
    Of Hermite series coefficients representing their product.

See Also
--------
hermeadd, hermesub, hermediv, hermepow

Notes
-----
In general, the (polynomial) product of two C-series results in terms
that are not in the Hermite polynomial basis set.  Thus, to express
the product as a Hermite series, it is necessary to "reproject" the
product onto said basis set, which may produce "unintuitive" (but
correct) results; see Examples section below.

Examples
--------
>>> from numpy.polynomial.hermite_e import hermemul
>>> hermemul([1, 2, 3], [0, 1, 2])
array([ 14.,  15.,  28.,   7.,   6.])


from .polynomial import polyadd, polysub, polymulx<EOL>[c] = pu.as_series([c])<EOL>n = len(c)<EOL>if n == <NUM_LIT:1>:<EOL><INDENT>return c<EOL><DEDENT>if n == <NUM_LIT:2>:<EOL><INDENT>return c<EOL><DEDENT>else:<EOL><INDENT>c0 = c[-<NUM_LIT:2>]<EOL>c1 = c[-<NUM_LIT:1>]<EOL>for i in range(n - <NUM_LIT:1>, <NUM_LIT:1>, -<NUM_LIT:1>):<EOL><INDENT>tmp = c0<EOL>c0 = polysub(c[i - <NUM_LIT:2>], c1*(i - <NUM_LIT:1>))<EOL>c1 = polyadd(tmp, polymulx(c1))<EOL><DEDENT>return polyadd(c0, polymulx(c1))<EOL><DEDENT>

Convert a Hermite series to a polynomial.

Convert an array representing the coefficients of a Hermite series,
ordered from lowest degree to highest, to an array of the coefficients
of the equivalent polynomial (relative to the "standard" basis) ordered
from lowest to highest degree.

Parameters
----------
c : array_like
    1-D array containing the Hermite series coefficients, ordered
    from lowest order term to highest.

Returns
-------
pol : ndarray
    1-D array containing the coefficients of the equivalent polynomial
    (relative to the "standard" basis) ordered from lowest order term
    to highest.

See Also
--------
poly2herme

Notes
-----
The easy way to do conversions between polynomial basis sets
is to use the convert method of a class instance.

Examples
--------
>>> from numpy.polynomial.hermite_e import herme2poly
>>> herme2poly([  2.,  10.,   2.,   3.])
array([ 0.,  1.,  2.,  3.])


def hermepow(c, pow, maxpower=<NUM_LIT:16>):

<EOL>[c] = pu.as_series([c])<EOL>power = int(pow)<EOL>if power != pow or power < <NUM_LIT:0>:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>elif maxpower is not None and power > maxpower:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>elif power == <NUM_LIT:0>:<EOL><INDENT>return np.array([<NUM_LIT:1>], dtype=c.dtype)<EOL><DEDENT>elif power == <NUM_LIT:1>:<EOL><INDENT>return c<EOL><DEDENT>else:<EOL><INDENT>prd = c<EOL>for i in range(<NUM_LIT:2>, power + <NUM_LIT:1>):<EOL><INDENT>prd = hermemul(prd, c)<EOL><DEDENT>return prd<EOL><DEDENT>

Raise a Hermite series to a power.

    Returns the Hermite series `c` raised to the power `pow`. The
    argument `c` is a sequence of coefficients ordered from low to high.
    i.e., [1,2,3] is the series  ``P_0 + 2*P_1 + 3*P_2.``

    Parameters
    ----------
    c : array_like
        1-D array of Hermite series coefficients ordered from low to
        high.
    pow : integer
        Power to which the series will be raised
    maxpower : integer, optional
        Maximum power allowed. This is mainly to limit growth of the series
        to unmanageable size. Default is 16

    Returns
    -------
    coef : ndarray
        Hermite series of power.

    See Also
    --------
    hermeadd, hermesub, hermemul, hermediv

    Examples
    --------
    >>> from numpy.polynomial.hermite_e import hermepow
    >>> hermepow([1, 2, 3], 2)
    array([ 23.,  28.,  46.,  12.,   9.])


w = np.exp(-<NUM_LIT>*x**<NUM_LIT:2>)<EOL>return w<EOL>

Weight function of the Hermite_e polynomials.

    The weight function is :math:`\exp(-x^2/2)` and the interval of
    integration is :math:`[-\inf, \inf]`. the HermiteE polynomials are
    orthogonal, but not normalized, with respect to this weight function.

    Parameters
    ----------
    x : array_like
       Values at which the weight function will be computed.

    Returns
    -------
    w : ndarray
       The weight function at `x`.

    Notes
    -----

    .. versionadded::1.7.0


def hermefit(x, y, deg, rcond=None, full=False, w=None):

order = int(deg) + <NUM_LIT:1><EOL>x = np.asarray(x) + <NUM_LIT:0.0><EOL>y = np.asarray(y) + <NUM_LIT:0.0><EOL>if deg < <NUM_LIT:0>:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if x.ndim != <NUM_LIT:1>:<EOL><INDENT>raise TypeError("<STR_LIT>")<EOL><DEDENT>if x.size == <NUM_LIT:0>:<EOL><INDENT>raise TypeError("<STR_LIT>")<EOL><DEDENT>if y.ndim < <NUM_LIT:1> or y.ndim > <NUM_LIT:2>:<EOL><INDENT>raise TypeError("<STR_LIT>")<EOL><DEDENT>if len(x) != len(y):<EOL><INDENT>raise TypeError("<STR_LIT>")<EOL><DEDENT>lhs = hermevander(x, deg).T<EOL>rhs = y.T<EOL>if w is not None:<EOL><INDENT>w = np.asarray(w) + <NUM_LIT:0.0><EOL>if w.ndim != <NUM_LIT:1>:<EOL><INDENT>raise TypeError("<STR_LIT>")<EOL><DEDENT>if len(x) != len(w):<EOL><INDENT>raise TypeError("<STR_LIT>")<EOL><DEDENT>lhs = lhs * w<EOL>rhs = rhs * w<EOL><DEDENT>if rcond is None:<EOL><INDENT>rcond = len(x)*np.finfo(x.dtype).eps<EOL><DEDENT>if issubclass(lhs.dtype.type, np.complexfloating):<EOL><INDENT>scl = np.sqrt((np.square(lhs.real) + np.square(lhs.imag)).sum(<NUM_LIT:1>))<EOL><DEDENT>else:<EOL><INDENT>scl = np.sqrt(np.square(lhs).sum(<NUM_LIT:1>))<EOL><DEDENT>scl[scl == <NUM_LIT:0>] = <NUM_LIT:1><EOL>c, resids, rank, s = la.lstsq(lhs.T/scl, rhs.T, rcond)<EOL>c = (c.T/scl).T<EOL>if rank != order and not full:<EOL><INDENT>msg = "<STR_LIT>"<EOL>warnings.warn(msg, pu.RankWarning)<EOL><DEDENT>if full:<EOL><INDENT>return c, [resids, rank, s, rcond]<EOL><DEDENT>else:<EOL><INDENT>return c<EOL><DEDENT>

Least squares fit of Hermite series to data.

Return the coefficients of a HermiteE series of degree `deg` that is
the least squares fit to the data values `y` given at points `x`. If
`y` is 1-D the returned coefficients will also be 1-D. If `y` is 2-D
multiple fits are done, one for each column of `y`, and the resulting
coefficients are stored in the corresponding columns of a 2-D return.
The fitted polynomial(s) are in the form

.. math::  p(x) = c_0 + c_1 * He_1(x) + ... + c_n * He_n(x),

where `n` is `deg`.

Parameters
----------
x : array_like, shape (M,)
    x-coordinates of the M sample points ``(x[i], y[i])``.
y : array_like, shape (M,) or (M, K)
    y-coordinates of the sample points. Several data sets of sample
    points sharing the same x-coordinates can be fitted at once by
    passing in a 2D-array that contains one dataset per column.
deg : int
    Degree of the fitting polynomial
rcond : float, optional
    Relative condition number of the fit. Singular values smaller than
    this relative to the largest singular value will be ignored. The
    default value is len(x)*eps, where eps is the relative precision of
    the float type, about 2e-16 in most cases.
full : bool, optional
    Switch determining nature of return value. When it is False (the
    default) just the coefficients are returned, when True diagnostic
    information from the singular value decomposition is also returned.
w : array_like, shape (`M`,), optional
    Weights. If not None, the contribution of each point
    ``(x[i],y[i])`` to the fit is weighted by `w[i]`. Ideally the
    weights are chosen so that the errors of the products ``w[i]*y[i]``
    all have the same variance.  The default value is None.

Returns
-------
coef : ndarray, shape (M,) or (M, K)
    Hermite coefficients ordered from low to high. If `y` was 2-D,
    the coefficients for the data in column k  of `y` are in column
    `k`.

[residuals, rank, singular_values, rcond] : list
    These values are only returned if `full` = True

    resid -- sum of squared residuals of the least squares fit
    rank -- the numerical rank of the scaled Vandermonde matrix
    sv -- singular values of the scaled Vandermonde matrix
    rcond -- value of `rcond`.

    For more details, see `linalg.lstsq`.

Warns
-----
RankWarning
    The rank of the coefficient matrix in the least-squares fit is
    deficient. The warning is only raised if `full` = False.  The
    warnings can be turned off by

    >>> import warnings
    >>> warnings.simplefilter('ignore', RankWarning)

See Also
--------
chebfit, legfit, polyfit, hermfit, polyfit
hermeval : Evaluates a Hermite series.
hermevander : pseudo Vandermonde matrix of Hermite series.
hermeweight : HermiteE weight function.
linalg.lstsq : Computes a least-squares fit from the matrix.
scipy.interpolate.UnivariateSpline : Computes spline fits.

Notes
-----
The solution is the coefficients of the HermiteE series `p` that
minimizes the sum of the weighted squared errors

.. math:: E = \\sum_j w_j^2 * |y_j - p(x_j)|^2,

where the :math:`w_j` are the weights. This problem is solved by
setting up the (typically) overdetermined matrix equation

.. math:: V(x) * c = w * y,

where `V` is the pseudo Vandermonde matrix of `x`, the elements of `c`
are the coefficients to be solved for, and the elements of `y` are the
observed values.  This equation is then solved using the singular value
decomposition of `V`.

If some of the singular values of `V` are so small that they are
neglected, then a `RankWarning` will be issued. This means that the
coefficient values may be poorly determined. Using a lower order fit
will usually get rid of the warning.  The `rcond` parameter can also be
set to a value smaller than its default, but the resulting fit may be
spurious and have large contributions from roundoff error.

Fits using HermiteE series are probably most useful when the data can
be approximated by ``sqrt(w(x)) * p(x)``, where `w(x)` is the HermiteE
weight. In that case the weight ``sqrt(w(x[i])`` should be used
together with data values ``y[i]/sqrt(w(x[i])``. The weight function is
available as `hermeweight`.

References
----------
.. [1] Wikipedia, "Curve fitting",
       http://en.wikipedia.org/wiki/Curve_fitting

Examples
--------
>>> from numpy.polynomial.hermite_e import hermefik, hermeval
>>> x = np.linspace(-10, 10)
>>> err = np.random.randn(len(x))/10
>>> y = hermeval(x, [1, 2, 3]) + err
>>> hermefit(x, y, 2)
array([ 1.01690445,  1.99951418,  2.99948696])


w = np.exp(-x)<EOL>return w<EOL>

Weight function of the Laguerre polynomials.

    The weight function is :math:`exp(-x)` and the interval of integration
    is :math:`[0, \inf]`. The Laguerre polynomials are orthogonal, but not
    normalized, with respect to this weight function.

    Parameters
    ----------
    x : array_like
       Values at which the weight function will be computed.

    Returns
    -------
    w : ndarray
       The weight function at `x`.

    Notes
    -----

    .. versionadded::1.7.0


try:<EOL><INDENT>x, y, z = np.array((x, y, z), copy=<NUM_LIT:0>)<EOL><DEDENT>except:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>c = lagval(x, c)<EOL>c = lagval(y, c, tensor=False)<EOL>c = lagval(z, c, tensor=False)<EOL>return c<EOL>

Evaluate a 3-D Laguerre series at points (x, y, z).

This function returns the values:

.. math:: p(x,y,z) = \\sum_{i,j,k} c_{i,j,k} * L_i(x) * L_j(y) * L_k(z)

The parameters `x`, `y`, and `z` are converted to arrays only if
they are tuples or a lists, otherwise they are treated as a scalars and
they must have the same shape after conversion. In either case, either
`x`, `y`, and `z` or their elements must support multiplication and
addition both with themselves and with the elements of `c`.

If `c` has fewer than 3 dimensions, ones are implicitly appended to its
shape to make it 3-D. The shape of the result will be c.shape[3:] +
x.shape.

Parameters
----------
x, y, z : array_like, compatible object
    The three dimensional series is evaluated at the points
    `(x, y, z)`, where `x`, `y`, and `z` must have the same shape.  If
    any of `x`, `y`, or `z` is a list or tuple, it is first converted
    to an ndarray, otherwise it is left unchanged and if it isn't an
    ndarray it is  treated as a scalar.
c : array_like
    Array of coefficients ordered so that the coefficient of the term of
    multi-degree i,j,k is contained in ``c[i,j,k]``. If `c` has dimension
    greater than 3 the remaining indices enumerate multiple sets of
    coefficients.

Returns
-------
values : ndarray, compatible object
    The values of the multidimension polynomial on points formed with
    triples of corresponding values from `x`, `y`, and `z`.

See Also
--------
lagval, lagval2d, laggrid2d, laggrid3d

Notes
-----

.. versionadded::1.7.0


try:<EOL><INDENT>x, y = np.array((x, y), copy=<NUM_LIT:0>)<EOL><DEDENT>except:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>c = lagval(x, c)<EOL>c = lagval(y, c, tensor=False)<EOL>return c<EOL>

Evaluate a 2-D Laguerre series at points (x, y).

This function returns the values:

.. math:: p(x,y) = \\sum_{i,j} c_{i,j} * L_i(x) * L_j(y)

The parameters `x` and `y` are converted to arrays only if they are
tuples or a lists, otherwise they are treated as a scalars and they
must have the same shape after conversion. In either case, either `x`
and `y` or their elements must support multiplication and addition both
with themselves and with the elements of `c`.

If `c` is a 1-D array a one is implicitly appended to its shape to make
it 2-D. The shape of the result will be c.shape[2:] + x.shape.

Parameters
----------
x, y : array_like, compatible objects
    The two dimensional series is evaluated at the points `(x, y)`,
    where `x` and `y` must have the same shape. If `x` or `y` is a list
    or tuple, it is first converted to an ndarray, otherwise it is left
    unchanged and if it isn't an ndarray it is treated as a scalar.
c : array_like
    Array of coefficients ordered so that the coefficient of the term
    of multi-degree i,j is contained in ``c[i,j]``. If `c` has
    dimension greater than two the remaining indices enumerate multiple
    sets of coefficients.

Returns
-------
values : ndarray, compatible object
    The values of the two dimensional polynomial at points formed with
    pairs of corresponding values from `x` and `y`.

See Also
--------
lagval, laggrid2d, lagval3d, laggrid3d

Notes
-----

.. versionadded::1.7.0


ideg = int(deg)<EOL>if ideg != deg or ideg < <NUM_LIT:1>:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>c = np.array([<NUM_LIT:0>]*deg + [<NUM_LIT:1>])<EOL>m = lagcompanion(c)<EOL>x = la.eigvals(m)<EOL>x.sort()<EOL>dy = lagval(x, c)<EOL>df = lagval(x, lagder(c))<EOL>x -= dy/df<EOL>fm = lagval(x, c[<NUM_LIT:1>:])<EOL>fm /= np.abs(fm).max()<EOL>df /= np.abs(df).max()<EOL>w = <NUM_LIT:1>/(fm * df)<EOL>w /= w.sum()<EOL>return x, w<EOL>

Gauss-Laguerre quadrature.

Computes the sample points and weights for Gauss-Laguerre quadrature.
These sample points and weights will correctly integrate polynomials of
degree :math:`2*deg - 1` or less over the interval :math:`[0, \inf]`
with the weight function :math:`f(x) = \exp(-x)`.

Parameters
----------
deg : int
    Number of sample points and weights. It must be >= 1.

Returns
-------
x : ndarray
    1-D ndarray containing the sample points.
y : ndarray
    1-D ndarray containing the weights.

Notes
-----

.. versionadded::1.7.0

The results have only been tested up to degree 100 higher degrees may
be problematic. The weights are determined by using the fact that

.. math:: w_k = c / (L'_n(x_k) * L_{n-1}(x_k))

where :math:`c` is a constant independent of :math:`k` and :math:`x_k`
is the k'th root of :math:`L_n`, and then scaling the results to get
the right value when integrating 1.


c = np.array(c, ndmin=<NUM_LIT:1>, copy=<NUM_LIT:0>)<EOL>if c.dtype.char in '<STR_LIT>':<EOL><INDENT>c = c.astype(np.double)<EOL><DEDENT>if isinstance(x, (tuple, list)):<EOL><INDENT>x = np.asarray(x)<EOL><DEDENT>if isinstance(x, np.ndarray) and tensor:<EOL><INDENT>c = c.reshape(c.shape + (<NUM_LIT:1>,)*x.ndim)<EOL><DEDENT>if len(c) == <NUM_LIT:1>:<EOL><INDENT>c0 = c[<NUM_LIT:0>]<EOL>c1 = <NUM_LIT:0><EOL><DEDENT>elif len(c) == <NUM_LIT:2>:<EOL><INDENT>c0 = c[<NUM_LIT:0>]<EOL>c1 = c[<NUM_LIT:1>]<EOL><DEDENT>else:<EOL><INDENT>nd = len(c)<EOL>c0 = c[-<NUM_LIT:2>]<EOL>c1 = c[-<NUM_LIT:1>]<EOL>for i in range(<NUM_LIT:3>, len(c) + <NUM_LIT:1>):<EOL><INDENT>tmp = c0<EOL>nd = nd - <NUM_LIT:1><EOL>c0 = c[-i] - (c1*(nd - <NUM_LIT:1>))/nd<EOL>c1 = tmp + (c1*((<NUM_LIT:2>*nd - <NUM_LIT:1>) - x))/nd<EOL><DEDENT><DEDENT>return c0 + c1*(<NUM_LIT:1> - x)<EOL>

Evaluate a Laguerre series at points x.

If `c` is of length `n + 1`, this function returns the value:

.. math:: p(x) = c_0 * L_0(x) + c_1 * L_1(x) + ... + c_n * L_n(x)

The parameter `x` is converted to an array only if it is a tuple or a
list, otherwise it is treated as a scalar. In either case, either `x`
or its elements must support multiplication and addition both with
themselves and with the elements of `c`.

If `c` is a 1-D array, then `p(x)` will have the same shape as `x`.  If
`c` is multidimensional, then the shape of the result depends on the
value of `tensor`. If `tensor` is true the shape will be c.shape[1:] +
x.shape. If `tensor` is false the shape will be c.shape[1:]. Note that
scalars have shape (,).

Trailing zeros in the coefficients will be used in the evaluation, so
they should be avoided if efficiency is a concern.

Parameters
----------
x : array_like, compatible object
    If `x` is a list or tuple, it is converted to an ndarray, otherwise
    it is left unchanged and treated as a scalar. In either case, `x`
    or its elements must support addition and multiplication with
    with themselves and with the elements of `c`.
c : array_like
    Array of coefficients ordered so that the coefficients for terms of
    degree n are contained in c[n]. If `c` is multidimensional the
    remaining indices enumerate multiple polynomials. In the two
    dimensional case the coefficients may be thought of as stored in
    the columns of `c`.
tensor : boolean, optional
    If True, the shape of the coefficient array is extended with ones
    on the right, one for each dimension of `x`. Scalars have dimension 0
    for this action. The result is that every column of coefficients in
    `c` is evaluated for every element of `x`. If False, `x` is broadcast
    over the columns of `c` for the evaluation.  This keyword is useful
    when `c` is multidimensional. The default value is True.

    .. versionadded:: 1.7.0

Returns
-------
values : ndarray, algebra_like
    The shape of the return value is described above.

See Also
--------
lagval2d, laggrid2d, lagval3d, laggrid3d

Notes
-----
The evaluation uses Clenshaw recursion, aka synthetic division.

Examples
--------
>>> from numpy.polynomial.laguerre import lagval
>>> coef = [1,2,3]
>>> lagval(1, coef)
-0.5
>>> lagval([[1,2],[3,4]], coef)
array([[-0.5, -4. ],
       [-4.5, -2. ]])


def hermpow(c, pow, maxpower=<NUM_LIT:16>):

<EOL>[c] = pu.as_series([c])<EOL>power = int(pow)<EOL>if power != pow or power < <NUM_LIT:0>:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>elif maxpower is not None and power > maxpower:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>elif power == <NUM_LIT:0>:<EOL><INDENT>return np.array([<NUM_LIT:1>], dtype=c.dtype)<EOL><DEDENT>elif power == <NUM_LIT:1>:<EOL><INDENT>return c<EOL><DEDENT>else:<EOL><INDENT>prd = c<EOL>for i in range(<NUM_LIT:2>, power + <NUM_LIT:1>):<EOL><INDENT>prd = hermmul(prd, c)<EOL><DEDENT>return prd<EOL><DEDENT>

Raise a Hermite series to a power.

    Returns the Hermite series `c` raised to the power `pow`. The
    argument `c` is a sequence of coefficients ordered from low to high.
    i.e., [1,2,3] is the series  ``P_0 + 2*P_1 + 3*P_2.``

    Parameters
    ----------
    c : array_like
        1-D array of Hermite series coefficients ordered from low to
        high.
    pow : integer
        Power to which the series will be raised
    maxpower : integer, optional
        Maximum power allowed. This is mainly to limit growth of the series
        to unmanageable size. Default is 16

    Returns
    -------
    coef : ndarray
        Hermite series of power.

    See Also
    --------
    hermadd, hermsub, hermmul, hermdiv

    Examples
    --------
    >>> from numpy.polynomial.hermite import hermpow
    >>> hermpow([1, 2, 3], 2)
    array([ 81.,  52.,  82.,  12.,   9.])


<EOL>[c] = pu.as_series([c])<EOL>if len(c) <= <NUM_LIT:1>:<EOL><INDENT>return np.array([], dtype=c.dtype)<EOL><DEDENT>if len(c) == <NUM_LIT:2>:<EOL><INDENT>return np.array([-<NUM_LIT>*c[<NUM_LIT:0>]/c[<NUM_LIT:1>]])<EOL><DEDENT>m = hermcompanion(c)<EOL>r = la.eigvals(m)<EOL>r.sort()<EOL>return r<EOL>

Compute the roots of a Hermite series.

Return the roots (a.k.a. "zeros") of the polynomial

.. math:: p(x) = \\sum_i c[i] * H_i(x).

Parameters
----------
c : 1-D array_like
    1-D array of coefficients.

Returns
-------
out : ndarray
    Array of the roots of the series. If all the roots are real,
    then `out` is also real, otherwise it is complex.

See Also
--------
polyroots, legroots, lagroots, chebroots, hermeroots

Notes
-----
The root estimates are obtained as the eigenvalues of the companion
matrix, Roots far from the origin of the complex plane may have large
errors due to the numerical instability of the series for such
values. Roots with multiplicity greater than 1 will also show larger
errors as the value of the series near such points is relatively
insensitive to errors in the roots. Isolated roots near the origin can
be improved by a few iterations of Newton's method.

The Hermite series basis polynomials aren't powers of `x` so the
results of this function may seem unintuitive.

Examples
--------
>>> from numpy.polynomial.hermite import hermroots, hermfromroots
>>> coef = hermfromroots([-1, 0, 1])
>>> coef
array([ 0.   ,  0.25 ,  0.   ,  0.125])
>>> hermroots(coef)
array([ -1.00000000e+00,  -1.38777878e-17,   1.00000000e+00])


ideg = [int(d) for d in deg]<EOL>is_valid = [id == d and id >= <NUM_LIT:0> for id, d in zip(ideg, deg)]<EOL>if is_valid != [<NUM_LIT:1>, <NUM_LIT:1>, <NUM_LIT:1>]:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>degx, degy, degz = ideg<EOL>x, y, z = np.array((x, y, z), copy=<NUM_LIT:0>) + <NUM_LIT:0.0><EOL>vx = hermvander(x, degx)<EOL>vy = hermvander(y, degy)<EOL>vz = hermvander(z, degz)<EOL>v = vx[..., None, None]*vy[..., None,:, None]*vz[..., None, None,:]<EOL>return v.reshape(v.shape[:-<NUM_LIT:3>] + (-<NUM_LIT:1>,))<EOL>

Pseudo-Vandermonde matrix of given degrees.

    Returns the pseudo-Vandermonde matrix of degrees `deg` and sample
    points `(x, y, z)`. If `l, m, n` are the given degrees in `x, y, z`,
    then The pseudo-Vandermonde matrix is defined by

    .. math:: V[..., (m+1)(n+1)i + (n+1)j + k] = H_i(x)*H_j(y)*H_k(z),

    where `0 <= i <= l`, `0 <= j <= m`, and `0 <= j <= n`.  The leading
    indices of `V` index the points `(x, y, z)` and the last index encodes
    the degrees of the Hermite polynomials.

    If ``V = hermvander3d(x, y, z, [xdeg, ydeg, zdeg])``, then the columns
    of `V` correspond to the elements of a 3-D coefficient array `c` of
    shape (xdeg + 1, ydeg + 1, zdeg + 1) in the order

    .. math:: c_{000}, c_{001}, c_{002},... , c_{010}, c_{011}, c_{012},...

    and  ``np.dot(V, c.flat)`` and ``hermval3d(x, y, z, c)`` will be the
    same up to roundoff. This equivalence is useful both for least squares
    fitting and for the evaluation of a large number of 3-D Hermite
    series of the same degrees and sample points.

    Parameters
    ----------
    x, y, z : array_like
        Arrays of point coordinates, all of the same shape. The dtypes will
        be converted to either float64 or complex128 depending on whether
        any of the elements are complex. Scalars are converted to 1-D
        arrays.
    deg : list of ints
        List of maximum degrees of the form [x_deg, y_deg, z_deg].

    Returns
    -------
    vander3d : ndarray
        The shape of the returned matrix is ``x.shape + (order,)``, where
        :math:`order = (deg[0]+1)*(deg([1]+1)*(deg[2]+1)`.  The dtype will
        be the same as the converted `x`, `y`, and `z`.

    See Also
    --------
    hermvander, hermvander3d. hermval2d, hermval3d

    Notes
    -----

    .. versionadded::1.7.0


c = np.array(c, ndmin=<NUM_LIT:1>, copy=<NUM_LIT:0>)<EOL>if c.dtype.char in '<STR_LIT>':<EOL><INDENT>c = c.astype(np.double)<EOL><DEDENT>if isinstance(x, (tuple, list)):<EOL><INDENT>x = np.asarray(x)<EOL><DEDENT>if isinstance(x, np.ndarray) and tensor:<EOL><INDENT>c = c.reshape(c.shape + (<NUM_LIT:1>,)*x.ndim)<EOL><DEDENT>x2 = x*<NUM_LIT:2><EOL>if len(c) == <NUM_LIT:1>:<EOL><INDENT>c0 = c[<NUM_LIT:0>]<EOL>c1 = <NUM_LIT:0><EOL><DEDENT>elif len(c) == <NUM_LIT:2>:<EOL><INDENT>c0 = c[<NUM_LIT:0>]<EOL>c1 = c[<NUM_LIT:1>]<EOL><DEDENT>else:<EOL><INDENT>nd = len(c)<EOL>c0 = c[-<NUM_LIT:2>]<EOL>c1 = c[-<NUM_LIT:1>]<EOL>for i in range(<NUM_LIT:3>, len(c) + <NUM_LIT:1>):<EOL><INDENT>tmp = c0<EOL>nd = nd - <NUM_LIT:1><EOL>c0 = c[-i] - c1*(<NUM_LIT:2>*(nd - <NUM_LIT:1>))<EOL>c1 = tmp + c1*x2<EOL><DEDENT><DEDENT>return c0 + c1*x2<EOL>

Evaluate an Hermite series at points x.

If `c` is of length `n + 1`, this function returns the value:

.. math:: p(x) = c_0 * H_0(x) + c_1 * H_1(x) + ... + c_n * H_n(x)

The parameter `x` is converted to an array only if it is a tuple or a
list, otherwise it is treated as a scalar. In either case, either `x`
or its elements must support multiplication and addition both with
themselves and with the elements of `c`.

If `c` is a 1-D array, then `p(x)` will have the same shape as `x`.  If
`c` is multidimensional, then the shape of the result depends on the
value of `tensor`. If `tensor` is true the shape will be c.shape[1:] +
x.shape. If `tensor` is false the shape will be c.shape[1:]. Note that
scalars have shape (,).

Trailing zeros in the coefficients will be used in the evaluation, so
they should be avoided if efficiency is a concern.

Parameters
----------
x : array_like, compatible object
    If `x` is a list or tuple, it is converted to an ndarray, otherwise
    it is left unchanged and treated as a scalar. In either case, `x`
    or its elements must support addition and multiplication with
    with themselves and with the elements of `c`.
c : array_like
    Array of coefficients ordered so that the coefficients for terms of
    degree n are contained in c[n]. If `c` is multidimensional the
    remaining indices enumerate multiple polynomials. In the two
    dimensional case the coefficients may be thought of as stored in
    the columns of `c`.
tensor : boolean, optional
    If True, the shape of the coefficient array is extended with ones
    on the right, one for each dimension of `x`. Scalars have dimension 0
    for this action. The result is that every column of coefficients in
    `c` is evaluated for every element of `x`. If False, `x` is broadcast
    over the columns of `c` for the evaluation.  This keyword is useful
    when `c` is multidimensional. The default value is True.

    .. versionadded:: 1.7.0

Returns
-------
values : ndarray, algebra_like
    The shape of the return value is described above.

See Also
--------
hermval2d, hermgrid2d, hermval3d, hermgrid3d

Notes
-----
The evaluation uses Clenshaw recursion, aka synthetic division.

Examples
--------
>>> from numpy.polynomial.hermite import hermval
>>> coef = [1,2,3]
>>> hermval(1, coef)
11.0
>>> hermval([[1,2],[3,4]], coef)
array([[  11.,   51.],
       [ 115.,  203.]])


def hermder(c, m=<NUM_LIT:1>, scl=<NUM_LIT:1>, axis=<NUM_LIT:0>):

c = np.array(c, ndmin=<NUM_LIT:1>, copy=<NUM_LIT:1>)<EOL>if c.dtype.char in '<STR_LIT>':<EOL><INDENT>c = c.astype(np.double)<EOL><DEDENT>cnt, iaxis = [int(t) for t in [m, axis]]<EOL>if cnt != m:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if cnt < <NUM_LIT:0>:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if iaxis != axis:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if not -c.ndim <= iaxis < c.ndim:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if iaxis < <NUM_LIT:0>:<EOL><INDENT>iaxis += c.ndim<EOL><DEDENT>if cnt == <NUM_LIT:0>:<EOL><INDENT>return c<EOL><DEDENT>c = np.rollaxis(c, iaxis)<EOL>n = len(c)<EOL>if cnt >= n:<EOL><INDENT>c = c[:<NUM_LIT:1>]*<NUM_LIT:0><EOL><DEDENT>else:<EOL><INDENT>for i in range(cnt):<EOL><INDENT>n = n - <NUM_LIT:1><EOL>c *= scl<EOL>der = np.empty((n,) + c.shape[<NUM_LIT:1>:], dtype=c.dtype)<EOL>for j in range(n, <NUM_LIT:0>, -<NUM_LIT:1>):<EOL><INDENT>der[j - <NUM_LIT:1>] = (<NUM_LIT:2>*j)*c[j]<EOL><DEDENT>c = der<EOL><DEDENT><DEDENT>c = np.rollaxis(c, <NUM_LIT:0>, iaxis + <NUM_LIT:1>)<EOL>return c<EOL>

Differentiate a Hermite series.

Returns the Hermite series coefficients `c` differentiated `m` times
along `axis`.  At each iteration the result is multiplied by `scl` (the
scaling factor is for use in a linear change of variable). The argument
`c` is an array of coefficients from low to high degree along each
axis, e.g., [1,2,3] represents the series ``1*H_0 + 2*H_1 + 3*H_2``
while [[1,2],[1,2]] represents ``1*H_0(x)*H_0(y) + 1*H_1(x)*H_0(y) +
2*H_0(x)*H_1(y) + 2*H_1(x)*H_1(y)`` if axis=0 is ``x`` and axis=1 is
``y``.

Parameters
----------
c : array_like
    Array of Hermite series coefficients. If `c` is multidimensional the
    different axis correspond to different variables with the degree in
    each axis given by the corresponding index.
m : int, optional
    Number of derivatives taken, must be non-negative. (Default: 1)
scl : scalar, optional
    Each differentiation is multiplied by `scl`.  The end result is
    multiplication by ``scl**m``.  This is for use in a linear change of
    variable. (Default: 1)
axis : int, optional
    Axis over which the derivative is taken. (Default: 0).

    .. versionadded:: 1.7.0

Returns
-------
der : ndarray
    Hermite series of the derivative.

See Also
--------
hermint

Notes
-----
In general, the result of differentiating a Hermite series does not
resemble the same operation on a power series. Thus the result of this
function may be "unintuitive," albeit correct; see Examples section
below.

Examples
--------
>>> from numpy.polynomial.hermite import hermder
>>> hermder([ 1. ,  0.5,  0.5,  0.5])
array([ 1.,  2.,  3.])
>>> hermder([-0.5,  1./2.,  1./8.,  1./12.,  1./16.], m=2)
array([ 1.,  2.,  3.])


try:<EOL><INDENT>x, y, z = np.array((x, y, z), copy=<NUM_LIT:0>)<EOL><DEDENT>except:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>c = hermval(x, c)<EOL>c = hermval(y, c, tensor=False)<EOL>c = hermval(z, c, tensor=False)<EOL>return c<EOL>

Evaluate a 3-D Hermite series at points (x, y, z).

This function returns the values:

.. math:: p(x,y,z) = \\sum_{i,j,k} c_{i,j,k} * H_i(x) * H_j(y) * H_k(z)

The parameters `x`, `y`, and `z` are converted to arrays only if
they are tuples or a lists, otherwise they are treated as a scalars and
they must have the same shape after conversion. In either case, either
`x`, `y`, and `z` or their elements must support multiplication and
addition both with themselves and with the elements of `c`.

If `c` has fewer than 3 dimensions, ones are implicitly appended to its
shape to make it 3-D. The shape of the result will be c.shape[3:] +
x.shape.

Parameters
----------
x, y, z : array_like, compatible object
    The three dimensional series is evaluated at the points
    `(x, y, z)`, where `x`, `y`, and `z` must have the same shape.  If
    any of `x`, `y`, or `z` is a list or tuple, it is first converted
    to an ndarray, otherwise it is left unchanged and if it isn't an
    ndarray it is  treated as a scalar.
c : array_like
    Array of coefficients ordered so that the coefficient of the term of
    multi-degree i,j,k is contained in ``c[i,j,k]``. If `c` has dimension
    greater than 3 the remaining indices enumerate multiple sets of
    coefficients.

Returns
-------
values : ndarray, compatible object
    The values of the multidimensional polynomial on points formed with
    triples of corresponding values from `x`, `y`, and `z`.

See Also
--------
hermval, hermval2d, hermgrid2d, hermgrid3d

Notes
-----

.. versionadded::1.7.0


ideg = int(deg)<EOL>if ideg != deg:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if ideg < <NUM_LIT:0>:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>x = np.array(x, copy=<NUM_LIT:0>, ndmin=<NUM_LIT:1>) + <NUM_LIT:0.0><EOL>dims = (ideg + <NUM_LIT:1>,) + x.shape<EOL>dtyp = x.dtype<EOL>v = np.empty(dims, dtype=dtyp)<EOL>v[<NUM_LIT:0>] = x*<NUM_LIT:0> + <NUM_LIT:1><EOL>if ideg > <NUM_LIT:0>:<EOL><INDENT>x2 = x*<NUM_LIT:2><EOL>v[<NUM_LIT:1>] = x2<EOL>for i in range(<NUM_LIT:2>, ideg + <NUM_LIT:1>):<EOL><INDENT>v[i] = (v[i-<NUM_LIT:1>]*x2 - v[i-<NUM_LIT:2>]*(<NUM_LIT:2>*(i - <NUM_LIT:1>)))<EOL><DEDENT><DEDENT>return np.rollaxis(v, <NUM_LIT:0>, v.ndim)<EOL>

Pseudo-Vandermonde matrix of given degree.

    Returns the pseudo-Vandermonde matrix of degree `deg` and sample points
    `x`. The pseudo-Vandermonde matrix is defined by

    .. math:: V[..., i] = H_i(x),

    where `0 <= i <= deg`. The leading indices of `V` index the elements of
    `x` and the last index is the degree of the Hermite polynomial.

    If `c` is a 1-D array of coefficients of length `n + 1` and `V` is the
    array ``V = hermvander(x, n)``, then ``np.dot(V, c)`` and
    ``hermval(x, c)`` are the same up to roundoff. This equivalence is
    useful both for least squares fitting and for the evaluation of a large
    number of Hermite series of the same degree and sample points.

    Parameters
    ----------
    x : array_like
        Array of points. The dtype is converted to float64 or complex128
        depending on whether any of the elements are complex. If `x` is
        scalar it is converted to a 1-D array.
    deg : int
        Degree of the resulting matrix.

    Returns
    -------
    vander : ndarray
        The pseudo-Vandermonde matrix. The shape of the returned matrix is
        ``x.shape + (deg + 1,)``, where The last index is the degree of the
        corresponding Hermite polynomial.  The dtype will be the same as
        the converted `x`.

    Examples
    --------
    >>> from numpy.polynomial.hermite import hermvander
    >>> x = np.array([-1, 0, 1])
    >>> hermvander(x, 3)
    array([[ 1., -2.,  2.,  4.],
           [ 1.,  0., -2., -0.],
           [ 1.,  2.,  2., -4.]])


return np.all(self.window == other.window)<EOL>

Check if windows match.

        .. versionadded:: 1.6.0

        Parameters
        ----------
        other : class instance
            The other class must have the ``window`` attribute.

        Returns
        -------
        bool : boolean
            True if the windows are the same, False otherwise.


@classmethod<EOL><INDENT>def fromroots(cls, roots, domain=[], window=None):<DEDENT>

[roots] = pu.as_series([roots], trim=False)<EOL>if domain is None:<EOL><INDENT>domain = pu.getdomain(roots)<EOL><DEDENT>elif type(domain) is list and len(domain) == <NUM_LIT:0>:<EOL><INDENT>domain = cls.domain<EOL><DEDENT>if window is None:<EOL><INDENT>window = cls.window<EOL><DEDENT>deg = len(roots)<EOL>off, scl = pu.mapparms(domain, window)<EOL>rnew = off + scl*roots<EOL>coef = cls._fromroots(rnew) / scl**deg<EOL>return cls(coef, domain=domain, window=window)<EOL>

Return series instance that has the specified roots.

        Returns a series representing the product
        ``(x - r[0])*(x - r[1])*...*(x - r[n-1])``, where ``r`` is a
        list of roots.

        Parameters
        ----------
        roots : array_like
            List of roots.
        domain : {[], None, array_like}, optional
            Domain for the resulting series. If None the domain is the
            interval from the smallest root to the largest. If [] the
            domain is the class domain. The default is [].
        window : {None, array_like}, optional
            Window for the returned series. If None the class window is
            used. The default is None.

        Returns
        -------
        new_series : series
            Series with the specified roots.


return pu.mapparms(self.domain, self.window)<EOL>

Return the mapping parameters.

        The returned values define a linear map ``off + scl*x`` that is
        applied to the input arguments before the series is evaluated. The
        map depends on the ``domain`` and ``window``; if the current
        ``domain`` is equal to the ``window`` the resulting map is the
        identity.  If the coefficients of the series instance are to be
        used by themselves outside this class, then the linear function
        must be substituted for the ``x`` in the standard representation of
        the base polynomials.

        Returns
        -------
        off, scl : float or complex
            The mapping function is defined by ``off + scl*x``.

        Notes
        -----
        If the current domain is the interval ``[l1, r1]`` and the window
        is ``[l2, r2]``, then the linear mapping function ``L`` is
        defined by the equations::

            L(l1) = l2
            L(r1) = r2


@classmethod<EOL><INDENT>def identity(cls, domain=None, window=None):<DEDENT>

if domain is None:<EOL><INDENT>domain = cls.domain<EOL><DEDENT>if window is None:<EOL><INDENT>window = cls.window<EOL><DEDENT>off, scl = pu.mapparms(window, domain)<EOL>coef = cls._line(off, scl)<EOL>return cls(coef, domain, window)<EOL>

Identity function.

        If ``p`` is the returned series, then ``p(x) == x`` for all
        values of x.

        Parameters
        ----------
        domain : {None, array_like}, optional
            If given, the array must be of the form ``[beg, end]``, where
            ``beg`` and ``end`` are the endpoints of the domain. If None is
            given then the class domain is used. The default is None.
        window : {None, array_like}, optional
            If given, the resulting array must be if the form
            ``[beg, end]``, where ``beg`` and ``end`` are the endpoints of
            the window. If None is given then the class window is used. The
            default is None.

        Returns
        -------
        new_series : series
             Series of representing the identity.


def convert(self, domain=None, kind=None, window=None):

if kind is None:<EOL><INDENT>kind = self.__class__<EOL><DEDENT>if domain is None:<EOL><INDENT>domain = kind.domain<EOL><DEDENT>if window is None:<EOL><INDENT>window = kind.window<EOL><DEDENT>return self(kind.identity(domain, window=window))<EOL>

Convert series to a different kind and/or domain and/or window.

        Parameters
        ----------
        domain : array_like, optional
            The domain of the converted series. If the value is None,
            the default domain of `kind` is used.
        kind : class, optional
            The polynomial series type class to which the current instance
            should be converted. If kind is None, then the class of the
            current instance is used.
        window : array_like, optional
            The window of the converted series. If the value is None,
            the default window of `kind` is used.

        Returns
        -------
        new_series : series
            The returned class can be of different type than the current
            instance and/or have a different domain and/or different
            window.

        Notes
        -----
        Conversion between domains and class types can result in
        numerically ill defined series.

        Examples
        --------


x = np.asanyarray(x)<EOL>off, scl = mapparms(old, new)<EOL>return off + scl*x<EOL>

Apply linear map to input points.

The linear map ``offset + scale*x`` that maps the domain `old` to
the domain `new` is applied to the points `x`.

Parameters
----------
x : array_like
    Points to be mapped. If `x` is a subtype of ndarray the subtype
    will be preserved.
old, new : array_like
    The two domains that determine the map.  Each must (successfully)
    convert to 1-d arrays containing precisely two values.

Returns
-------
x_out : ndarray
    Array of points of the same shape as `x`, after application of the
    linear map between the two domains.

See Also
--------
getdomain, mapparms

Notes
-----
Effectively, this implements:

.. math ::
    x\\_out = new[0] + m(x - old[0])

where

.. math ::
    m = \\frac{new[1]-new[0]}{old[1]-old[0]}

Examples
--------
>>> from numpy import polynomial as P
>>> old_domain = (-1,1)
>>> new_domain = (0,2*np.pi)
>>> x = np.linspace(-1,1,6); x
array([-1. , -0.6, -0.2,  0.2,  0.6,  1. ])
>>> x_out = P.mapdomain(x, old_domain, new_domain); x_out
array([ 0.        ,  1.25663706,  2.51327412,  3.76991118,  5.02654825,
        6.28318531])
>>> x - P.mapdomain(x_out, new_domain, old_domain)
array([ 0.,  0.,  0.,  0.,  0.,  0.])

Also works for complex numbers (and thus can be used to map any line in
the complex plane to any other line therein).

>>> i = complex(0,1)
>>> old = (-1 - i, 1 + i)
>>> new = (-1 + i, 1 - i)
>>> z = np.linspace(old[0], old[1], 6); z
array([-1.0-1.j , -0.6-0.6j, -0.2-0.2j,  0.2+0.2j,  0.6+0.6j,  1.0+1.j ])
>>> new_z = P.mapdomain(z, old, new); new_z
array([-1.0+1.j , -0.6+0.6j, -0.2+0.2j,  0.2-0.2j,  0.6-0.6j,  1.0-1.j ])


oldlen = old[<NUM_LIT:1>] - old[<NUM_LIT:0>]<EOL>newlen = new[<NUM_LIT:1>] - new[<NUM_LIT:0>]<EOL>off = (old[<NUM_LIT:1>]*new[<NUM_LIT:0>] - old[<NUM_LIT:0>]*new[<NUM_LIT:1>])/oldlen<EOL>scl = newlen/oldlen<EOL>return off, scl<EOL>

Linear map parameters between domains.

Return the parameters of the linear map ``offset + scale*x`` that maps
`old` to `new` such that ``old[i] -> new[i]``, ``i = 0, 1``.

Parameters
----------
old, new : array_like
    Domains. Each domain must (successfully) convert to a 1-d array
    containing precisely two values.

Returns
-------
offset, scale : scalars
    The map ``L(x) = offset + scale*x`` maps the first domain to the
    second.

See Also
--------
getdomain, mapdomain

Notes
-----
Also works for complex numbers, and thus can be used to calculate the
parameters required to map any line in the complex plane to any other
line therein.

Examples
--------
>>> from numpy import polynomial as P
>>> P.mapparms((-1,1),(-1,1))
(0.0, 1.0)
>>> P.mapparms((1,-1),(-1,1))
(0.0, -1.0)
>>> i = complex(0,1)
>>> P.mapparms((-i,-1),(1,i))
((1+1j), (1+0j))


global lcb_map, cb_map<EOL>out_a = a<EOL>if isintent_out(var):<EOL><INDENT>for k in var['<STR_LIT>']:<EOL><INDENT>if k[:<NUM_LIT:4>]=='<STR_LIT>':<EOL><INDENT>out_a = k[<NUM_LIT:4>:]<EOL>break<EOL><DEDENT><DEDENT><DEDENT>ret={'<STR_LIT>':a,'<STR_LIT>':out_a}<EOL>ret['<STR_LIT>']=getctype(var)<EOL>intent_flags = []<EOL>for f, s in isintent_dict.items():<EOL><INDENT>if f(var): intent_flags.append('<STR_LIT>'%s)<EOL><DEDENT>if intent_flags:<EOL><INDENT>ret['<STR_LIT>'] = '<STR_LIT:|>'.join(intent_flags)<EOL><DEDENT>else:<EOL><INDENT>ret['<STR_LIT>'] = '<STR_LIT>'<EOL><DEDENT>if isarray(var): ret['<STR_LIT>']='<STR_LIT:N>'<EOL>elif ret['<STR_LIT>'] in c2buildvalue_map:<EOL><INDENT>ret['<STR_LIT>']=c2buildvalue_map[ret['<STR_LIT>']]<EOL><DEDENT>else: ret['<STR_LIT>']='<STR_LIT:O>'<EOL>ret['<STR_LIT>'], ret['<STR_LIT>']=getinit(a, var)<EOL>if hasinitvalue(var) and iscomplex(var) and not isarray(var):<EOL><INDENT>ret['<STR_LIT>'], ret['<STR_LIT>'] = markoutercomma(ret['<STR_LIT>'][<NUM_LIT:1>:-<NUM_LIT:1>]).split('<STR_LIT>')<EOL><DEDENT>if isexternal(var):<EOL><INDENT>ret['<STR_LIT>']=a<EOL>if a in lcb_map:<EOL><INDENT>ret['<STR_LIT>']=lcb_map[a]<EOL>ret['<STR_LIT>']=lcb2_map[lcb_map[a]]['<STR_LIT>']<EOL>ret['<STR_LIT>']=lcb2_map[lcb_map[a]]['<STR_LIT>']<EOL>ret['<STR_LIT>']=lcb2_map[lcb_map[a]]['<STR_LIT>']<EOL>ret['<STR_LIT>']=lcb2_map[lcb_map[a]]['<STR_LIT>']<EOL><DEDENT>else:<EOL><INDENT>ret['<STR_LIT>']=a<EOL>errmess('<STR_LIT>'%(a, list(lcb_map.keys())))<EOL><DEDENT><DEDENT>if isstring(var):<EOL><INDENT>ret['<STR_LIT>']=getstrlength(var)<EOL><DEDENT>if isarray(var):<EOL><INDENT>ret=dictappend(ret, getarrdims(a, var))<EOL>dim=copy.copy(var['<STR_LIT>'])<EOL><DEDENT>if ret['<STR_LIT>'] in c2capi_map:<EOL><INDENT>ret['<STR_LIT>']=c2capi_map[ret['<STR_LIT>']]<EOL><DEDENT>if debugcapi(var):<EOL><INDENT>il=[isintent_in, '<STR_LIT:input>', isintent_out, '<STR_LIT>',<EOL>isintent_inout, '<STR_LIT>', isrequired, '<STR_LIT>',<EOL>isoptional, '<STR_LIT>', isintent_hide, '<STR_LIT>',<EOL>iscomplex, '<STR_LIT>',<EOL>l_and(isscalar, l_not(iscomplex)), '<STR_LIT>',<EOL>isstring, '<STR_LIT:string>', isarray, '<STR_LIT>',<EOL>iscomplexarray, '<STR_LIT>', isstringarray, '<STR_LIT>',<EOL>iscomplexfunction, '<STR_LIT>',<EOL>l_and(isfunction, l_not(iscomplexfunction)), '<STR_LIT>',<EOL>isexternal, '<STR_LIT>',<EOL>isintent_callback, '<STR_LIT>',<EOL>isintent_aux, '<STR_LIT>',<EOL>]<EOL>rl=[]<EOL>for i in range(<NUM_LIT:0>, len(il), <NUM_LIT:2>):<EOL><INDENT>if il[i](var): rl.append(il[i+<NUM_LIT:1>])<EOL><DEDENT>if isstring(var):<EOL><INDENT>rl.append('<STR_LIT>'%(a, ret['<STR_LIT>']))<EOL><DEDENT>if isarray(var):<EOL><INDENT>if not isintent_c(var):<EOL><INDENT>var['<STR_LIT>'].reverse()<EOL>

varname,ctype,atype
init,init.r,init.i,pytype
vardebuginfo,vardebugshowvalue,varshowvalue
varrfromat
intent


a, _ = _makearray(a)<EOL>_assertRankAtLeast2(a)<EOL>_assertNdSquareness(a)<EOL>b, wrap = _makearray(b)<EOL>t, result_t = _commonType(a, b)<EOL>if b.ndim == a.ndim - <NUM_LIT:1>:<EOL><INDENT>if a.shape[-<NUM_LIT:1>] == <NUM_LIT:0> and b.shape[-<NUM_LIT:1>] == <NUM_LIT:0>:<EOL><INDENT>a = a.reshape(a.shape[:-<NUM_LIT:1>])<EOL>bc = broadcast(a, b)<EOL>return wrap(empty(bc.shape, dtype=result_t))<EOL><DEDENT>gufunc = _umath_linalg.solve1<EOL><DEDENT>else:<EOL><INDENT>if b.size == <NUM_LIT:0>:<EOL><INDENT>if (a.shape[-<NUM_LIT:1>] == <NUM_LIT:0> and b.shape[-<NUM_LIT:2>] == <NUM_LIT:0>) or b.shape[-<NUM_LIT:1>] == <NUM_LIT:0>:<EOL><INDENT>a = a[:,:<NUM_LIT:1>].reshape(a.shape[:-<NUM_LIT:1>] + (<NUM_LIT:1>,))<EOL>bc = broadcast(a, b)<EOL>return wrap(empty(bc.shape, dtype=result_t))<EOL><DEDENT><DEDENT>gufunc = _umath_linalg.solve<EOL><DEDENT>signature = '<STR_LIT>' if isComplexType(t) else '<STR_LIT>'<EOL>extobj = get_linalg_error_extobj(_raise_linalgerror_singular)<EOL>r = gufunc(a, b, signature=signature, extobj=extobj)<EOL>return wrap(r.astype(result_t))<EOL>

Solve a linear matrix equation, or system of linear scalar equations.

Computes the "exact" solution, `x`, of the well-determined, i.e., full
rank, linear matrix equation `ax = b`.

Parameters
----------
a : (..., M, M) array_like
    Coefficient matrix.
b : {(..., M,), (..., M, K)}, array_like
    Ordinate or "dependent variable" values.

Returns
-------
x : {(..., M,), (..., M, K)} ndarray
    Solution to the system a x = b.  Returned shape is identical to `b`.

Raises
------
LinAlgError
    If `a` is singular or not square.

Notes
-----
Broadcasting rules apply, see the `numpy.linalg` documentation for
details.

The solutions are computed using LAPACK routine _gesv

`a` must be square and of full-rank, i.e., all rows (or, equivalently,
columns) must be linearly independent; if either is not true, use
`lstsq` for the least-squares best "solution" of the
system/equation.

References
----------
.. [1] G. Strang, *Linear Algebra and Its Applications*, 2nd Ed., Orlando,
       FL, Academic Press, Inc., 1980, pg. 22.

Examples
--------
Solve the system of equations ``3 * x0 + x1 = 9`` and ``x0 + 2 * x1 = 8``:

>>> a = np.array([[3,1], [1,2]])
>>> b = np.array([9,8])
>>> x = np.linalg.solve(a, b)
>>> x
array([ 2.,  3.])

Check that the solution is correct:

>>> np.allclose(np.dot(a, x), b)
True


a = asarray(a)<EOL>oldshape = a.shape<EOL>prod = <NUM_LIT:1><EOL>if ind > <NUM_LIT:0>:<EOL><INDENT>invshape = oldshape[ind:] + oldshape[:ind]<EOL>for k in oldshape[ind:]:<EOL><INDENT>prod *= k<EOL><DEDENT><DEDENT>else:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>a = a.reshape(prod, -<NUM_LIT:1>)<EOL>ia = inv(a)<EOL>return ia.reshape(*invshape)<EOL>

Compute the 'inverse' of an N-dimensional array.

The result is an inverse for `a` relative to the tensordot operation
``tensordot(a, b, ind)``, i. e., up to floating-point accuracy,
``tensordot(tensorinv(a), a, ind)`` is the "identity" tensor for the
tensordot operation.

Parameters
----------
a : array_like
    Tensor to 'invert'. Its shape must be 'square', i. e.,
    ``prod(a.shape[:ind]) == prod(a.shape[ind:])``.
ind : int, optional
    Number of first indices that are involved in the inverse sum.
    Must be a positive integer, default is 2.

Returns
-------
b : ndarray
    `a`'s tensordot inverse, shape ``a.shape[ind:] + a.shape[:ind]``.

Raises
------
LinAlgError
    If `a` is singular or not 'square' (in the above sense).

See Also
--------
tensordot, tensorsolve

Examples
--------
>>> a = np.eye(4*6)
>>> a.shape = (4, 6, 8, 3)
>>> ainv = np.linalg.tensorinv(a, ind=2)
>>> ainv.shape
(8, 3, 4, 6)
>>> b = np.random.randn(4, 6)
>>> np.allclose(np.tensordot(ainv, b), np.linalg.tensorsolve(a, b))
True

>>> a = np.eye(4*6)
>>> a.shape = (24, 8, 3)
>>> ainv = np.linalg.tensorinv(a, ind=1)
>>> ainv.shape
(8, 3, 24)
>>> b = np.random.randn(24)
>>> np.allclose(np.tensordot(ainv, b, 1), np.linalg.tensorsolve(a, b))
True


UPLO = UPLO.upper()<EOL>if UPLO not in ('<STR_LIT:L>', '<STR_LIT>'):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>extobj = get_linalg_error_extobj(<EOL>_raise_linalgerror_eigenvalues_nonconvergence)<EOL>if UPLO == '<STR_LIT:L>':<EOL><INDENT>gufunc = _umath_linalg.eigvalsh_lo<EOL><DEDENT>else:<EOL><INDENT>gufunc = _umath_linalg.eigvalsh_up<EOL><DEDENT>a, wrap = _makearray(a)<EOL>_assertNoEmpty2d(a)<EOL>_assertRankAtLeast2(a)<EOL>_assertNdSquareness(a)<EOL>t, result_t = _commonType(a)<EOL>signature = '<STR_LIT>' if isComplexType(t) else '<STR_LIT>'<EOL>w = gufunc(a, signature=signature, extobj=extobj)<EOL>return w.astype(_realType(result_t))<EOL>

Compute the eigenvalues of a Hermitian or real symmetric matrix.

Main difference from eigh: the eigenvectors are not computed.

Parameters
----------
a : (..., M, M) array_like
    A complex- or real-valued matrix whose eigenvalues are to be
    computed.
UPLO : {'L', 'U'}, optional
    Same as `lower`, with 'L' for lower and 'U' for upper triangular.
    Deprecated.

Returns
-------
w : (..., M,) ndarray
    The eigenvalues, not necessarily ordered, each repeated according to
    its multiplicity.

Raises
------
LinAlgError
    If the eigenvalue computation does not converge.

See Also
--------
eigh : eigenvalues and eigenvectors of symmetric/Hermitian arrays.
eigvals : eigenvalues of general real or complex arrays.
eig : eigenvalues and right eigenvectors of general real or complex
      arrays.

Notes
-----
Broadcasting rules apply, see the `numpy.linalg` documentation for
details.

The eigenvalues are computed using LAPACK routines _ssyevd, _heevd

Examples
--------
>>> from numpy import linalg as LA
>>> a = np.array([[1, -2j], [2j, 5]])
>>> LA.eigvalsh(a)
array([ 0.17157288+0.j,  5.82842712+0.j])


UPLO = UPLO.upper()<EOL>if UPLO not in ('<STR_LIT:L>', '<STR_LIT>'):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>a, wrap = _makearray(a)<EOL>_assertRankAtLeast2(a)<EOL>_assertNdSquareness(a)<EOL>t, result_t = _commonType(a)<EOL>extobj = get_linalg_error_extobj(<EOL>_raise_linalgerror_eigenvalues_nonconvergence)<EOL>if UPLO == '<STR_LIT:L>':<EOL><INDENT>gufunc = _umath_linalg.eigh_lo<EOL><DEDENT>else:<EOL><INDENT>gufunc = _umath_linalg.eigh_up<EOL><DEDENT>signature = '<STR_LIT>' if isComplexType(t) else '<STR_LIT>'<EOL>w, vt = gufunc(a, signature=signature, extobj=extobj)<EOL>w = w.astype(_realType(result_t))<EOL>vt = vt.astype(result_t)<EOL>return w, wrap(vt)<EOL>

Return the eigenvalues and eigenvectors of a Hermitian or symmetric matrix.

Returns two objects, a 1-D array containing the eigenvalues of `a`, and
a 2-D square array or matrix (depending on the input type) of the
corresponding eigenvectors (in columns).

Parameters
----------
A : (..., M, M) array
    Hermitian/Symmetric matrices whose eigenvalues and
    eigenvectors are to be computed.
UPLO : {'L', 'U'}, optional
    Specifies whether the calculation is done with the lower triangular
    part of `a` ('L', default) or the upper triangular part ('U').

Returns
-------
w : (..., M) ndarray
    The eigenvalues, not necessarily ordered.
v : {(..., M, M) ndarray, (..., M, M) matrix}
    The column ``v[:, i]`` is the normalized eigenvector corresponding
    to the eigenvalue ``w[i]``.  Will return a matrix object if `a` is
    a matrix object.

Raises
------
LinAlgError
    If the eigenvalue computation does not converge.

See Also
--------
eigvalsh : eigenvalues of symmetric or Hermitian arrays.
eig : eigenvalues and right eigenvectors for non-symmetric arrays.
eigvals : eigenvalues of non-symmetric arrays.

Notes
-----
Broadcasting rules apply, see the `numpy.linalg` documentation for
details.

The eigenvalues/eigenvectors are computed using LAPACK routines _ssyevd,
_heevd

The eigenvalues of real symmetric or complex Hermitian matrices are
always real. [1]_ The array `v` of (column) eigenvectors is unitary
and `a`, `w`, and `v` satisfy the equations
``dot(a, v[:, i]) = w[i] * v[:, i]``.

References
----------
.. [1] G. Strang, *Linear Algebra and Its Applications*, 2nd Ed., Orlando,
       FL, Academic Press, Inc., 1980, pg. 222.

Examples
--------
>>> from numpy import linalg as LA
>>> a = np.array([[1, -2j], [2j, 5]])
>>> a
array([[ 1.+0.j,  0.-2.j],
       [ 0.+2.j,  5.+0.j]])
>>> w, v = LA.eigh(a)
>>> w; v
array([ 0.17157288,  5.82842712])
array([[-0.92387953+0.j        , -0.38268343+0.j        ],
       [ 0.00000000+0.38268343j,  0.00000000-0.92387953j]])

>>> np.dot(a, v[:, 0]) - w[0] * v[:, 0] # verify 1st e-val/vec pair
array([2.77555756e-17 + 0.j, 0. + 1.38777878e-16j])
>>> np.dot(a, v[:, 1]) - w[1] * v[:, 1] # verify 2nd e-val/vec pair
array([ 0.+0.j,  0.+0.j])

>>> A = np.matrix(a) # what happens if input is a matrix object
>>> A
matrix([[ 1.+0.j,  0.-2.j],
        [ 0.+2.j,  5.+0.j]])
>>> w, v = LA.eigh(A)
>>> w; v
array([ 0.17157288,  5.82842712])
matrix([[-0.92387953+0.j        , -0.38268343+0.j        ],
        [ 0.00000000+0.38268343j,  0.00000000-0.92387953j]])


a, wrap = _makearray(a)<EOL>_assertRankAtLeast2(a)<EOL>_assertNdSquareness(a)<EOL>t, result_t = _commonType(a)<EOL>if a.shape[-<NUM_LIT:1>] == <NUM_LIT:0>:<EOL><INDENT>return wrap(empty_like(a, dtype=result_t))<EOL><DEDENT>signature = '<STR_LIT>' if isComplexType(t) else '<STR_LIT>'<EOL>extobj = get_linalg_error_extobj(_raise_linalgerror_singular)<EOL>ainv = _umath_linalg.inv(a, signature=signature, extobj=extobj)<EOL>return wrap(ainv.astype(result_t))<EOL>

Compute the (multiplicative) inverse of a matrix.

Given a square matrix `a`, return the matrix `ainv` satisfying
``dot(a, ainv) = dot(ainv, a) = eye(a.shape[0])``.

Parameters
----------
a : (..., M, M) array_like
    Matrix to be inverted.

Returns
-------
ainv : (..., M, M) ndarray or matrix
    (Multiplicative) inverse of the matrix `a`.

Raises
------
LinAlgError
    If `a` is not square or inversion fails.

Notes
-----
Broadcasting rules apply, see the `numpy.linalg` documentation for
details.

Examples
--------
>>> from numpy.linalg import inv
>>> a = np.array([[1., 2.], [3., 4.]])
>>> ainv = inv(a)
>>> np.allclose(np.dot(a, ainv), np.eye(2))
True
>>> np.allclose(np.dot(ainv, a), np.eye(2))
True

If a is a matrix object, then the return value is a matrix as well:

>>> ainv = inv(np.matrix(a))
>>> ainv
matrix([[-2. ,  1. ],
        [ 1.5, -0.5]])

Inverses of several matrices can be computed at once:

>>> a = np.array([[[1., 2.], [3., 4.]], [[1, 3], [3, 5]]])
>>> inv(a)
array([[[-2. ,  1. ],
        [ 1.5, -0.5]],
       [[-5. ,  2. ],
        [ 3. , -1. ]]])


x = asarray(x)<EOL>if ord is None and axis is None:<EOL><INDENT>x = x.ravel(order='<STR_LIT>')<EOL>if isComplexType(x.dtype.type):<EOL><INDENT>sqnorm = dot(x.real, x.real) + dot(x.imag, x.imag)<EOL><DEDENT>else:<EOL><INDENT>sqnorm = dot(x, x)<EOL><DEDENT>return sqrt(sqnorm)<EOL><DEDENT>nd = x.ndim<EOL>if axis is None:<EOL><INDENT>axis = tuple(range(nd))<EOL><DEDENT>elif not isinstance(axis, tuple):<EOL><INDENT>axis = (axis,)<EOL><DEDENT>if len(axis) == <NUM_LIT:1>:<EOL><INDENT>if ord == Inf:<EOL><INDENT>return abs(x).max(axis=axis)<EOL><DEDENT>elif ord == -Inf:<EOL><INDENT>return abs(x).min(axis=axis)<EOL><DEDENT>elif ord == <NUM_LIT:0>:<EOL><INDENT>return (x != <NUM_LIT:0>).sum(axis=axis)<EOL><DEDENT>elif ord == <NUM_LIT:1>:<EOL><INDENT>return add.reduce(abs(x), axis=axis)<EOL><DEDENT>elif ord is None or ord == <NUM_LIT:2>:<EOL><INDENT>s = (x.conj() * x).real<EOL>return sqrt(add.reduce(s, axis=axis))<EOL><DEDENT>else:<EOL><INDENT>try:<EOL><INDENT>ord + <NUM_LIT:1><EOL><DEDENT>except TypeError:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if x.dtype.type is longdouble:<EOL><INDENT>absx = abs(x)<EOL><DEDENT>else:<EOL><INDENT>absx = x if isComplexType(x.dtype.type) else asfarray(x)<EOL>if absx.dtype is x.dtype:<EOL><INDENT>absx = abs(absx)<EOL><DEDENT>else:<EOL><INDENT>abs(absx, out=absx)<EOL><DEDENT><DEDENT>absx **= ord<EOL>return add.reduce(absx, axis=axis) ** (<NUM_LIT:1.0> / ord)<EOL><DEDENT><DEDENT>elif len(axis) == <NUM_LIT:2>:<EOL><INDENT>row_axis, col_axis = axis<EOL>if not (-nd <= row_axis < nd and -nd <= col_axis < nd):<EOL><INDENT>raise ValueError('<STR_LIT>' %<EOL>(axis, x.shape))<EOL><DEDENT>if row_axis % nd == col_axis % nd:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>if ord == <NUM_LIT:2>:<EOL><INDENT>return _multi_svd_norm(x, row_axis, col_axis, amax)<EOL><DEDENT>elif ord == -<NUM_LIT:2>:<EOL><INDENT>return _multi_svd_norm(x, row_axis, col_axis, amin)<EOL><DEDENT>elif ord == <NUM_LIT:1>:<EOL><INDENT>if col_axis > row_axis:<EOL><INDENT>col_axis -= <NUM_LIT:1><EOL><DEDENT>return add.reduce(abs(x), axis=row_axis).max(axis=col_axis)<EOL><DEDENT>elif ord == Inf:<EOL><INDENT>if row_axis > col_axis:<EOL><INDENT>row_axis -= <NUM_LIT:1><EOL><DEDENT>return add.reduce(abs(x), axis=col_axis).max(axis=row_axis)<EOL><DEDENT>elif ord == -<NUM_LIT:1>:<EOL><INDENT>if col_axis > row_axis:<EOL><INDENT>col_axis -= <NUM_LIT:1><EOL><DEDENT>return add.reduce(abs(x), axis=row_axis).min(axis=col_axis)<EOL><DEDENT>elif ord == -Inf:<EOL><INDENT>if row_axis > col_axis:<EOL><INDENT>row_axis -= <NUM_LIT:1><EOL><DEDENT>return add.reduce(abs(x), axis=col_axis).min(axis=row_axis)<EOL><DEDENT>elif ord in [None, '<STR_LIT>', '<STR_LIT:f>']:<EOL><INDENT>return sqrt(add.reduce((x.conj() * x).real, axis=axis))<EOL><DEDENT>else:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT><DEDENT>else:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>

Matrix or vector norm.

This function is able to return one of seven different matrix norms,
or one of an infinite number of vector norms (described below), depending
on the value of the ``ord`` parameter.

Parameters
----------
x : array_like
    Input array.  If `axis` is None, `x` must be 1-D or 2-D.
ord : {non-zero int, inf, -inf, 'fro'}, optional
    Order of the norm (see table under ``Notes``). inf means numpy's
    `inf` object.
axis : {int, 2-tuple of ints, None}, optional
    If `axis` is an integer, it specifies the axis of `x` along which to
    compute the vector norms.  If `axis` is a 2-tuple, it specifies the
    axes that hold 2-D matrices, and the matrix norms of these matrices
    are computed.  If `axis` is None then either a vector norm (when `x`
    is 1-D) or a matrix norm (when `x` is 2-D) is returned.

Returns
-------
n : float or ndarray
    Norm of the matrix or vector(s).

Notes
-----
For values of ``ord <= 0``, the result is, strictly speaking, not a
mathematical 'norm', but it may still be useful for various numerical
purposes.

The following norms can be calculated:

=====  ============================  ==========================
ord    norm for matrices             norm for vectors
=====  ============================  ==========================
None   Frobenius norm                2-norm
'fro'  Frobenius norm                --
inf    max(sum(abs(x), axis=1))      max(abs(x))
-inf   min(sum(abs(x), axis=1))      min(abs(x))
0      --                            sum(x != 0)
1      max(sum(abs(x), axis=0))      as below
-1     min(sum(abs(x), axis=0))      as below
2      2-norm (largest sing. value)  as below
-2     smallest singular value       as below
other  --                            sum(abs(x)**ord)**(1./ord)
=====  ============================  ==========================

The Frobenius norm is given by [1]_:

    :math:`||A||_F = [\\sum_{i,j} abs(a_{i,j})^2]^{1/2}`

References
----------
.. [1] G. H. Golub and C. F. Van Loan, *Matrix Computations*,
       Baltimore, MD, Johns Hopkins University Press, 1985, pg. 15

Examples
--------
>>> from numpy import linalg as LA
>>> a = np.arange(9) - 4
>>> a
array([-4, -3, -2, -1,  0,  1,  2,  3,  4])
>>> b = a.reshape((3, 3))
>>> b
array([[-4, -3, -2],
       [-1,  0,  1],
       [ 2,  3,  4]])

>>> LA.norm(a)
7.745966692414834
>>> LA.norm(b)
7.745966692414834
>>> LA.norm(b, 'fro')
7.745966692414834
>>> LA.norm(a, np.inf)
4
>>> LA.norm(b, np.inf)
9
>>> LA.norm(a, -np.inf)
0
>>> LA.norm(b, -np.inf)
2

>>> LA.norm(a, 1)
20
>>> LA.norm(b, 1)
7
>>> LA.norm(a, -1)
-4.6566128774142013e-010
>>> LA.norm(b, -1)
6
>>> LA.norm(a, 2)
7.745966692414834
>>> LA.norm(b, 2)
7.3484692283495345

>>> LA.norm(a, -2)
nan
>>> LA.norm(b, -2)
1.8570331885190563e-016
>>> LA.norm(a, 3)
5.8480354764257312
>>> LA.norm(a, -3)
nan

Using the `axis` argument to compute vector norms:

>>> c = np.array([[ 1, 2, 3],
...               [-1, 1, 4]])
>>> LA.norm(c, axis=0)
array([ 1.41421356,  2.23606798,  5.        ])
>>> LA.norm(c, axis=1)
array([ 3.74165739,  4.24264069])
>>> LA.norm(c, ord=1, axis=1)
array([6, 6])

Using the `axis` argument to compute matrix norms:

>>> m = np.arange(8).reshape(2,2,2)
>>> LA.norm(m, axis=(1,2))
array([  3.74165739,  11.22497216])
>>> LA.norm(m[0, :, :]), LA.norm(m[1, :, :])
(3.7416573867739413, 11.224972160321824)


a, wrap = _makearray(a)<EOL>b = asarray(b)<EOL>an = a.ndim<EOL>if axes is not None:<EOL><INDENT>allaxes = list(range(<NUM_LIT:0>, an))<EOL>for k in axes:<EOL><INDENT>allaxes.remove(k)<EOL>allaxes.insert(an, k)<EOL><DEDENT>a = a.transpose(allaxes)<EOL><DEDENT>oldshape = a.shape[-(an-b.ndim):]<EOL>prod = <NUM_LIT:1><EOL>for k in oldshape:<EOL><INDENT>prod *= k<EOL><DEDENT>a = a.reshape(-<NUM_LIT:1>, prod)<EOL>b = b.ravel()<EOL>res = wrap(solve(a, b))<EOL>res.shape = oldshape<EOL>return res<EOL>

Solve the tensor equation ``a x = b`` for x.

It is assumed that all indices of `x` are summed over in the product,
together with the rightmost indices of `a`, as is done in, for example,
``tensordot(a, x, axes=len(b.shape))``.

Parameters
----------
a : array_like
    Coefficient tensor, of shape ``b.shape + Q``. `Q`, a tuple, equals
    the shape of that sub-tensor of `a` consisting of the appropriate
    number of its rightmost indices, and must be such that
   ``prod(Q) == prod(b.shape)`` (in which sense `a` is said to be
   'square').
b : array_like
    Right-hand tensor, which can be of any shape.
axes : tuple of ints, optional
    Axes in `a` to reorder to the right, before inversion.
    If None (default), no reordering is done.

Returns
-------
x : ndarray, shape Q

Raises
------
LinAlgError
    If `a` is singular or not 'square' (in the above sense).

See Also
--------
tensordot, tensorinv, einsum

Examples
--------
>>> a = np.eye(2*3*4)
>>> a.shape = (2*3, 4, 2, 3, 4)
>>> b = np.random.randn(2*3, 4)
>>> x = np.linalg.tensorsolve(a, b)
>>> x.shape
(2, 3, 4)
>>> np.allclose(np.tensordot(a, x, axes=3), b)
True


return isinstance(object, types.MethodType)<EOL>

Return true if the object is an instance method.

    Instance method objects provide these attributes:
        __doc__         documentation string
        __name__        name with which this method was defined
        im_class        class object in which this method belongs
        im_func         function object containing implementation of method
        im_self         instance to which this method is bound, or None


def formatargspec(args, varargs=None, varkw=None, defaults=None,<EOL>formatarg=str,<EOL>formatvarargs=lambda name: '<STR_LIT:*>' + name,<EOL>formatvarkw=lambda name: '<STR_LIT>' + name,<EOL>formatvalue=lambda value: '<STR_LIT:=>' + repr(value),<EOL>join=joinseq):

specs = []<EOL>if defaults:<EOL><INDENT>firstdefault = len(args) - len(defaults)<EOL><DEDENT>for i in range(len(args)):<EOL><INDENT>spec = strseq(args[i], formatarg, join)<EOL>if defaults and i >= firstdefault:<EOL><INDENT>spec = spec + formatvalue(defaults[i - firstdefault])<EOL><DEDENT>specs.append(spec)<EOL><DEDENT>if varargs is not None:<EOL><INDENT>specs.append(formatvarargs(varargs))<EOL><DEDENT>if varkw is not None:<EOL><INDENT>specs.append(formatvarkw(varkw))<EOL><DEDENT>return '<STR_LIT:(>' + '<STR_LIT:U+002CU+0020>'.join(specs) + '<STR_LIT:)>'<EOL>

Format an argument spec from the 4 values returned by getargspec.

    The first four arguments are (args, varargs, varkw, defaults).  The
    other four arguments are the corresponding optional formatting functions
    that are called to turn names and values into strings.  The ninth
    argument is an optional function to format the sequence of arguments.


def strseq(object, convert, join=joinseq):

if type(object) in [list, tuple]:<EOL><INDENT>return join([strseq(_o, convert, join) for _o in object])<EOL><DEDENT>else:<EOL><INDENT>return convert(object)<EOL><DEDENT>

Recursively walk a sequence, stringifying each element.


args, varargs, varkw = getargs(frame.f_code)<EOL>return args, varargs, varkw, frame.f_locals<EOL>

Get information about arguments passed into a particular frame.

    A tuple of four things is returned: (args, varargs, varkw, locals).
    'args' is a list of the argument names (it may contain nested lists).
    'varargs' and 'varkw' are the names of the * and ** arguments or None.
    'locals' is the locals dictionary of the given frame.


def ediff1d(arr, to_end=None, to_begin=None):

arr = ma.asanyarray(arr).flat<EOL>ed = arr[<NUM_LIT:1>:] - arr[:-<NUM_LIT:1>]<EOL>arrays = [ed]<EOL>if to_begin is not None:<EOL><INDENT>arrays.insert(<NUM_LIT:0>, to_begin)<EOL><DEDENT>if to_end is not None:<EOL><INDENT>arrays.append(to_end)<EOL><DEDENT>if len(arrays) != <NUM_LIT:1>:<EOL><INDENT>ed = hstack(arrays)<EOL><DEDENT>return ed<EOL>

Compute the differences between consecutive elements of an array.

This function is the equivalent of `numpy.ediff1d` that takes masked
values into account, see `numpy.ediff1d` for details.

See Also
--------
numpy.ediff1d : Equivalent function for ndarrays.


<EOL>if mask.ndim > <NUM_LIT:1>:<EOL><INDENT>mask = mask.ravel()<EOL><DEDENT>idx = (mask[<NUM_LIT:1>:] ^ mask[:-<NUM_LIT:1>]).nonzero()<EOL>idx = idx[<NUM_LIT:0>] + <NUM_LIT:1><EOL>slices = [slice(left, right)<EOL>for (left, right) in zip(itertools.chain([<NUM_LIT:0>], idx),<EOL>itertools.chain(idx, [len(mask)]),)]<EOL>return slices<EOL>

Finds the clumps (groups of data with the same values) for a 1D bool array.

Returns a series of slices.


def corrcoef(x, y=None, rowvar=True, bias=False, allow_masked=True, ddof=None):

<EOL>if ddof is not None and ddof != int(ddof):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if ddof is None:<EOL><INDENT>if bias:<EOL><INDENT>ddof = <NUM_LIT:0><EOL><DEDENT>else:<EOL><INDENT>ddof = <NUM_LIT:1><EOL><DEDENT><DEDENT>(x, xnotmask, rowvar) = _covhelper(x, y, rowvar, allow_masked)<EOL>if not rowvar:<EOL><INDENT>fact = np.dot(xnotmask.T, xnotmask) * <NUM_LIT:1.> - ddof<EOL>c = (dot(x.T, x.conj(), strict=False) / fact).squeeze()<EOL><DEDENT>else:<EOL><INDENT>fact = np.dot(xnotmask, xnotmask.T) * <NUM_LIT:1.> - ddof<EOL>c = (dot(x, x.T.conj(), strict=False) / fact).squeeze()<EOL><DEDENT>try:<EOL><INDENT>diag = ma.diagonal(c)<EOL><DEDENT>except ValueError:<EOL><INDENT>return <NUM_LIT:1><EOL><DEDENT>if xnotmask.all():<EOL><INDENT>_denom = ma.sqrt(ma.multiply.outer(diag, diag))<EOL><DEDENT>else:<EOL><INDENT>_denom = diagflat(diag)<EOL>n = x.shape[<NUM_LIT:1> - rowvar]<EOL>if rowvar:<EOL><INDENT>for i in range(n - <NUM_LIT:1>):<EOL><INDENT>for j in range(i + <NUM_LIT:1>, n):<EOL><INDENT>_x = mask_cols(vstack((x[i], x[j]))).var(axis=<NUM_LIT:1>, ddof=ddof)<EOL>_denom[i, j] = _denom[j, i] = ma.sqrt(ma.multiply.reduce(_x))<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>for i in range(n - <NUM_LIT:1>):<EOL><INDENT>for j in range(i + <NUM_LIT:1>, n):<EOL><INDENT>_x = mask_cols(<EOL>vstack((x[:, i], x[:, j]))).var(axis=<NUM_LIT:1>, ddof=ddof)<EOL>_denom[i, j] = _denom[j, i] = ma.sqrt(ma.multiply.reduce(_x))<EOL><DEDENT><DEDENT><DEDENT><DEDENT>return c / _denom<EOL>

Return correlation coefficients of the input array.

Except for the handling of missing data this function does the same as
`numpy.corrcoef`. For more details and examples, see `numpy.corrcoef`.

Parameters
----------
x : array_like
    A 1-D or 2-D array containing multiple variables and observations.
    Each row of `x` represents a variable, and each column a single
    observation of all those variables. Also see `rowvar` below.
y : array_like, optional
    An additional set of variables and observations. `y` has the same
    shape as `x`.
rowvar : bool, optional
    If `rowvar` is True (default), then each row represents a
    variable, with observations in the columns. Otherwise, the relationship
    is transposed: each column represents a variable, while the rows
    contain observations.
bias : bool, optional
    Default normalization (False) is by ``(N-1)``, where ``N`` is the
    number of observations given (unbiased estimate). If `bias` is 1,
    then normalization is by ``N``. This keyword can be overridden by
    the keyword ``ddof`` in numpy versions >= 1.5.
allow_masked : bool, optional
    If True, masked values are propagated pair-wise: if a value is masked
    in `x`, the corresponding value is masked in `y`.
    If False, raises an exception.
ddof : {None, int}, optional
    .. versionadded:: 1.5
    If not ``None`` normalization is by ``(N - ddof)``, where ``N`` is
    the number of observations; this overrides the value implied by
    ``bias``. The default value is ``None``.

See Also
--------
numpy.corrcoef : Equivalent function in top-level NumPy module.
cov : Estimate the covariance matrix.


def cov(x, y=None, rowvar=True, bias=False, allow_masked=True, ddof=None):

<EOL>if ddof is not None and ddof != int(ddof):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if ddof is None:<EOL><INDENT>if bias:<EOL><INDENT>ddof = <NUM_LIT:0><EOL><DEDENT>else:<EOL><INDENT>ddof = <NUM_LIT:1><EOL><DEDENT><DEDENT>(x, xnotmask, rowvar) = _covhelper(x, y, rowvar, allow_masked)<EOL>if not rowvar:<EOL><INDENT>fact = np.dot(xnotmask.T, xnotmask) * <NUM_LIT:1.> - ddof<EOL>result = (dot(x.T, x.conj(), strict=False) / fact).squeeze()<EOL><DEDENT>else:<EOL><INDENT>fact = np.dot(xnotmask, xnotmask.T) * <NUM_LIT:1.> - ddof<EOL>result = (dot(x, x.T.conj(), strict=False) / fact).squeeze()<EOL><DEDENT>return result<EOL>

Estimate the covariance matrix.

Except for the handling of missing data this function does the same as
`numpy.cov`. For more details and examples, see `numpy.cov`.

By default, masked values are recognized as such. If `x` and `y` have the
same shape, a common mask is allocated: if ``x[i,j]`` is masked, then
``y[i,j]`` will also be masked.
Setting `allow_masked` to False will raise an exception if values are
missing in either of the input arrays.

Parameters
----------
x : array_like
    A 1-D or 2-D array containing multiple variables and observations.
    Each row of `x` represents a variable, and each column a single
    observation of all those variables. Also see `rowvar` below.
y : array_like, optional
    An additional set of variables and observations. `y` has the same
    form as `x`.
rowvar : bool, optional
    If `rowvar` is True (default), then each row represents a
    variable, with observations in the columns. Otherwise, the relationship
    is transposed: each column represents a variable, while the rows
    contain observations.
bias : bool, optional
    Default normalization (False) is by ``(N-1)``, where ``N`` is the
    number of observations given (unbiased estimate). If `bias` is True,
    then normalization is by ``N``. This keyword can be overridden by
    the keyword ``ddof`` in numpy versions >= 1.5.
allow_masked : bool, optional
    If True, masked values are propagated pair-wise: if a value is masked
    in `x`, the corresponding value is masked in `y`.
    If False, raises a `ValueError` exception when some values are missing.
ddof : {None, int}, optional
    .. versionadded:: 1.5
    If not ``None`` normalization is by ``(N - ddof)``, where ``N`` is
    the number of observations; this overrides the value implied by
    ``bias``. The default value is ``None``.

Raises
------
ValueError
    Raised if some values are missing and `allow_masked` is False.

See Also
--------
numpy.cov


x = asarray(x)<EOL>if x.ndim != <NUM_LIT:2>:<EOL><INDENT>raise NotImplementedError("<STR_LIT>")<EOL><DEDENT>m = getmask(x)<EOL>if m is nomask or not m.any():<EOL><INDENT>return x._data<EOL><DEDENT>if m.all():<EOL><INDENT>return nxarray([])<EOL><DEDENT>(idxr, idxc) = (list(range(len(x))), list(range(x.shape[<NUM_LIT:1>])))<EOL>masked = m.nonzero()<EOL>if not axis:<EOL><INDENT>for i in np.unique(masked[<NUM_LIT:0>]):<EOL><INDENT>idxr.remove(i)<EOL><DEDENT><DEDENT>if axis in [None, <NUM_LIT:1>, -<NUM_LIT:1>]:<EOL><INDENT>for j in np.unique(masked[<NUM_LIT:1>]):<EOL><INDENT>idxc.remove(j)<EOL><DEDENT><DEDENT>return x._data[idxr][:, idxc]<EOL>

Suppress the rows and/or columns of a 2-D array that contain
masked values.

The suppression behavior is selected with the `axis` parameter.

- If axis is None, both rows and columns are suppressed.
- If axis is 0, only rows are suppressed.
- If axis is 1 or -1, only columns are suppressed.

Parameters
----------
axis : int, optional
    Axis along which to perform the operation. Default is None.

Returns
-------
compressed_array : ndarray
    The compressed array.

Examples
--------
>>> x = np.ma.array(np.arange(9).reshape(3, 3), mask=[[1, 0, 0],
...                                                   [1, 0, 0],
...                                                   [0, 0, 0]])
>>> x
masked_array(data =
 [[-- 1 2]
 [-- 4 5]
 [6 7 8]],
             mask =
 [[ True False False]
 [ True False False]
 [False False False]],
       fill_value = 999999)

>>> np.ma.extras.compress_rowcols(x)
array([[7, 8]])
>>> np.ma.extras.compress_rowcols(x, 0)
array([[6, 7, 8]])
>>> np.ma.extras.compress_rowcols(x, 1)
array([[1, 2],
       [4, 5],
       [7, 8]])