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

Skip to content

Vectorize and document simple_linear_interpolation. #9860

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 28, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 19 additions & 17 deletions lib/matplotlib/cbook/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1557,24 +1557,26 @@ def get_siblings(self, a):


def simple_linear_interpolation(a, steps):
if steps == 1:
return a

steps = int(np.floor(steps))
new_length = ((len(a) - 1) * steps) + 1
new_shape = list(a.shape)
new_shape[0] = new_length
result = np.zeros(new_shape, a.dtype)

result[0] = a[0]
a0 = a[0:-1]
a1 = a[1:]
delta = ((a1 - a0) / steps)
for i in range(1, steps):
result[i::steps] = delta * i + a0
result[steps::steps] = a1
"""
Resample an array with ``steps - 1`` points between original point pairs.

return result
Parameters
----------
a : array, shape (n, ...)
steps : int

Returns
-------
array, shape ``((n - 1) * steps + 1, ...)``

Along each column of *a*, ``(steps - 1)`` points are introduced between
each original values; the values are linearly interpolated.
"""
fps = a.reshape((len(a), -1))
xp = np.arange(len(a)) * steps
x = np.arange((len(a) - 1) * steps + 1)
return (np.column_stack([np.interp(x, xp, fp) for fp in fps.T])
.reshape((len(x),) + a.shape[1:]))


@deprecated('2.1', alternative='shutil.rmtree')
Expand Down