Analyze Data/Python Libraries

numpy-linspace, interp

Naranjito 2023. 5. 30. 10:27
  • linspace

numpy.linspace(start, stop, num=50, endpoint=True, retstep=False, dtype=None, axis=0)

 

Return evenly spaced numbers over a specified interval.

Returns num evenly spaced samples, calculated over the interval [start, stop].


endpoint : bool, optional
If True, stop is the last sample. Otherwise, it is not included. Default is True.

retstep : bool, optional
If True, return (samples, step), where step is the spacing between samples.

np.linspace(2.0, 3.0, num=5)
>>>
array([2.  , 2.25, 2.5 , 2.75, 3.  ])

np.linspace(2.0, 3.0, num=5, endpoint=False)
>>>
array([2. ,  2.2,  2.4,  2.6,  2.8])

np.linspace(2.0, 3.0, num=5, retstep=True)
>>>
(array([2.  ,  2.25,  2.5 ,  2.75,  3.  ]), 0.25)

 

  • interp

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.

 

x : array_like

The x-coordinates at which to evaluate the interpolated values.

 

xp : 1-D sequence of floats

The x-coordinates of the data points, must be increasing if argument period is not specified. Otherwise, xp is internally sorted after normalizing the periodic boundaries with xp = xp % period.

 

fp : 1-D sequence of float or complex

The y-coordinates of the data points, same length as xp.

xp = [1, 2, 3]
fp = [3, 2, 0]
np.interp(2.5, xp, fp)
>>>
1.0

np.interp([0, 1, 1.5, 2.72, 3.14], xp, fp)
>>>
array([3.  , 3.  , 2.5 , 0.56, 0.  ])

'Analyze Data > Python Libraries' 카테고리의 다른 글

numpy-concatenate  (0) 2023.06.07
numpy-identity  (0) 2023.06.02
numpy-np.c_[] VS np.r_[]  (0) 2023.05.25
numpy-axis, expand_dims  (0) 2023.05.24
numpy-random  (0) 2022.12.29