summaryrefslogtreecommitdiff
path: root/numpy/lib/arraypad.py
diff options
context:
space:
mode:
authorCharles Harris <charlesr.harris@gmail.com>2020-12-13 14:14:49 -0700
committerGitHub <noreply@github.com>2020-12-13 14:14:49 -0700
commit3fe2d9d2627fc0f84aeed293ff8afa7c1f08d899 (patch)
tree2ea27fe06a19c39e8d7a5fe2f87cb7e05363247d /numpy/lib/arraypad.py
parent7d7e446fcbeeff70d905bde2eb0264a797488280 (diff)
parenteff302e5e8678fa17fb3d8156d49eb585b0876d9 (diff)
downloadnumpy-3fe2d9d2627fc0f84aeed293ff8afa7c1f08d899.tar.gz
Merge branch 'master' into fix-issue-10244
Diffstat (limited to 'numpy/lib/arraypad.py')
-rw-r--r--numpy/lib/arraypad.py31
1 files changed, 14 insertions, 17 deletions
diff --git a/numpy/lib/arraypad.py b/numpy/lib/arraypad.py
index 7569e7651..8830b8147 100644
--- a/numpy/lib/arraypad.py
+++ b/numpy/lib/arraypad.py
@@ -207,23 +207,20 @@ def _get_linear_ramps(padded, axis, width_pair, end_value_pair):
"""
edge_pair = _get_edges(padded, axis, width_pair)
- left_ramp = np.linspace(
- start=end_value_pair[0],
- stop=edge_pair[0].squeeze(axis), # Dimensions is replaced by linspace
- num=width_pair[0],
- endpoint=False,
- dtype=padded.dtype,
- axis=axis,
- )
-
- right_ramp = np.linspace(
- start=end_value_pair[1],
- stop=edge_pair[1].squeeze(axis), # Dimension is replaced by linspace
- num=width_pair[1],
- endpoint=False,
- dtype=padded.dtype,
- axis=axis,
+ left_ramp, right_ramp = (
+ np.linspace(
+ start=end_value,
+ stop=edge.squeeze(axis), # Dimension is replaced by linspace
+ num=width,
+ endpoint=False,
+ dtype=padded.dtype,
+ axis=axis
+ )
+ for end_value, edge, width in zip(
+ end_value_pair, edge_pair, width_pair
+ )
)
+
# Reverse linear space in appropriate dimension
right_ramp = right_ramp[_slice_at_axis(slice(None, None, -1), axis)]
@@ -783,7 +780,7 @@ def pad(array, pad_width, mode='constant', **kwargs):
try:
unsupported_kwargs = set(kwargs) - set(allowed_kwargs[mode])
except KeyError:
- raise ValueError("mode '{}' is not supported".format(mode))
+ raise ValueError("mode '{}' is not supported".format(mode)) from None
if unsupported_kwargs:
raise ValueError("unsupported keyword arguments for mode '{}': {}"
.format(mode, unsupported_kwargs))