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)
| 1460 | |
| 1461 | @array_function_dispatch(_interp_dispatcher) |
| 1462 | def interp(x, xp, fp, left=None, right=None, period=None): |
| 1463 | """ |
| 1464 | One-dimensional linear interpolation for monotonically increasing sample points. |
| 1465 | |
| 1466 | Returns the one-dimensional piecewise linear interpolant to a function |
| 1467 | with given discrete data points (`xp`, `fp`), evaluated at `x`. |
| 1468 | |
| 1469 | Parameters |
| 1470 | ---------- |
| 1471 | x : array_like |
| 1472 | The x-coordinates at which to evaluate the interpolated values. |
| 1473 | |
| 1474 | xp : 1-D sequence of floats |
| 1475 | The x-coordinates of the data points, must be increasing if argument |
| 1476 | `period` is not specified. Otherwise, `xp` is internally sorted after |
| 1477 | normalizing the periodic boundaries with ``xp = xp % period``. |
| 1478 | |
| 1479 | fp : 1-D sequence of float or complex |
| 1480 | The y-coordinates of the data points, same length as `xp`. |
| 1481 | |
| 1482 | left : optional float or complex corresponding to fp |
| 1483 | Value to return for `x < xp[0]`, default is `fp[0]`. |
| 1484 | |
| 1485 | right : optional float or complex corresponding to fp |
| 1486 | Value to return for `x > xp[-1]`, default is `fp[-1]`. |
| 1487 | |
| 1488 | period : None or float, optional |
| 1489 | A period for the x-coordinates. This parameter allows the proper |
| 1490 | interpolation of angular x-coordinates. Parameters `left` and `right` |
| 1491 | are ignored if `period` is specified. |
| 1492 | |
| 1493 | .. versionadded:: 1.10.0 |
| 1494 | |
| 1495 | Returns |
| 1496 | ------- |
| 1497 | y : float or complex (corresponding to fp) or ndarray |
| 1498 | The interpolated values, same shape as `x`. |
| 1499 | |
| 1500 | Raises |
| 1501 | ------ |
| 1502 | ValueError |
| 1503 | If `xp` and `fp` have different length |
| 1504 | If `xp` or `fp` are not 1-D sequences |
| 1505 | If `period == 0` |
| 1506 | |
| 1507 | See Also |
| 1508 | -------- |
| 1509 | scipy.interpolate |
| 1510 | |
| 1511 | Warnings |
| 1512 | -------- |
| 1513 | The x-coordinate sequence is expected to be increasing, but this is not |
| 1514 | explicitly enforced. However, if the sequence `xp` is non-increasing, |
| 1515 | interpolation results are meaningless. |
| 1516 | |
| 1517 | Note that, since NaN is unsortable, `xp` also cannot contain NaNs. |
| 1518 | |
| 1519 | A simple check for `xp` being strictly increasing is:: |