MCPcopy
hub / github.com/numpy/numpy / interp

Function interp

numpy/lib/_function_base_impl.py:1550–1686  ·  view source on GitHub ↗

One-dimensional linear interpolation for monotonically increasing sample points. Returns the one-dimensional piecewise linear interpolant to a function with given discrete data points (`xp`, `fp`), evaluated at `x`. Parameters ---------- x : array_like The x-coordi

(x, xp, fp, left=None, right=None, period=None)

Source from the content-addressed store, hash-verified

1548
1549@array_function_dispatch(_interp_dispatcher)
1550def interp(x, xp, fp, left=None, right=None, period=None):
1551 """
1552 One-dimensional linear interpolation for monotonically increasing sample points.
1553
1554 Returns the one-dimensional piecewise linear interpolant to a function
1555 with given discrete data points (`xp`, `fp`), evaluated at `x`.
1556
1557 Parameters
1558 ----------
1559 x : array_like
1560 The x-coordinates at which to evaluate the interpolated values.
1561
1562 xp : 1-D sequence of floats
1563 The x-coordinates of the data points, must be increasing if argument
1564 `period` is not specified. Otherwise, `xp` is internally sorted after
1565 normalizing the periodic boundaries with ``xp = xp % period``.
1566
1567 fp : 1-D sequence of float or complex
1568 The y-coordinates of the data points, same length as `xp`.
1569
1570 left : optional float or complex corresponding to fp
1571 Value to return for `x < xp[0]`, default is `fp[0]`.
1572
1573 right : optional float or complex corresponding to fp
1574 Value to return for `x > xp[-1]`, default is `fp[-1]`.
1575
1576 period : None or float, optional
1577 A period for the x-coordinates. This parameter allows the proper
1578 interpolation of angular x-coordinates. Parameters `left` and `right`
1579 are ignored if `period` is specified.
1580
1581 Returns
1582 -------
1583 y : float or complex (corresponding to fp) or ndarray
1584 The interpolated values, same shape as `x`.
1585
1586 Raises
1587 ------
1588 ValueError
1589 If `xp` and `fp` have different length
1590 If `xp` or `fp` are not 1-D sequences
1591 If `period == 0`
1592
1593 See Also
1594 --------
1595 scipy.interpolate
1596
1597 Warnings
1598 --------
1599 The x-coordinate sequence is expected to be increasing, but this is not
1600 explicitly enforced. However, if the sequence `xp` is non-increasing,
1601 interpolation results are meaningless.
1602
1603 Note that, since NaN is unsortable, `xp` also cannot contain NaNs.
1604
1605 A simple check for `xp` being strictly increasing is::
1606
1607 np.all(np.diff(xp) > 0)

Callers 2

test_empty_xMethod · 0.90

Calls 1

argsortMethod · 0.45

Tested by 2

test_empty_xMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…