bundles / scipy 2.0.0.dev0+git20260907.41eeb59 / scipy / ndimage / _interpolation / zoom
function
scipy.ndimage._interpolation:zoom
source: build-install/usr/lib/python3.14/site-packages/scipy/ndimage/_interpolation.py:763
Signature
def zoom(input, zoom, output = None, order = 3, mode = constant, cval = 0.0, prefilter = True, *, grid_mode = False)Summary
Zoom an array.
Extended Summary
The array is zoomed using spline interpolation of the requested order.
Parameters
input: array_likeThe input array.
zoom: float or sequenceThe zoom factor along the axes. If a float,
zoomis the same for each axis. If a sequence,zoomshould contain one value for each axis.output: array or dtype, optionalThe array in which to place the output, or the dtype of the returned array. By default an array of the same dtype as input will be created.
order: int, optionalThe order of the spline interpolation, default is 3. The order has to be in the range 0-5.
mode: {'reflect', 'grid-mirror', 'constant', 'grid-constant', 'nearest', 'mirror', 'grid-wrap', 'wrap'}, optionalThe
modeparameter determines how the input array is extended beyond its boundaries. Default is 'constant'. Behavior for each valid value is as follows (see additional plots and details on boundary modes):'reflect' (
d c b a | a b c d | d c b a)The input is extended by reflecting about the edge of the last pixel. This mode is also sometimes referred to as half-sample symmetric.
'grid-mirror'
This is a synonym for 'reflect'.
'constant' (
k k k k | a b c d | k k k k)The input is extended by filling all values beyond the edge with the same constant value, defined by the
cvalparameter. No interpolation is performed beyond the edges of the input.'grid-constant' (
k k k k | a b c d | k k k k)The input is extended by filling all values beyond the edge with the same constant value, defined by the
cvalparameter. Interpolation occurs for samples outside the input's extent as well.'nearest' (
a a a a | a b c d | d d d d)The input is extended by replicating the last pixel.
'mirror' (
d c b | a b c d | c b a)The input is extended by reflecting about the center of the last pixel. This mode is also sometimes referred to as whole-sample symmetric.
'grid-wrap' (
a b c d | a b c d | a b c d)The input is extended by wrapping around to the opposite edge.
'wrap' (
b c d b c | a b c d | b c a b c)The input is extended by wrapping around to the opposite edge, but in a way such that the last point and initial point exactly overlap. In this case it is not well defined which sample will be chosen at the point of overlap.
For the example illustrated above, the edge values
aanddoverlap, while the inner patternb crepeats. The example demonstrates one possible output, whileb c a b c | a b c d | b c d b cis another, since eitheraordmay occur at each point of overlap.
cval: scalar, optionalValue to fill past edges of input if
modeis 'constant'. Default is 0.0.prefilter: bool, optionalDetermines if the input array is prefiltered with spline_filter before interpolation. The default is True, which will create a temporary
float64array of filtered values iforder > 1. If setting this to False, the output will be slightly blurred iforder > 1, unless the input is prefiltered, i.e. it is the result of calling spline_filter on the original input.grid_mode: bool, optionalIf False, the distance from the pixel centers is zoomed. Otherwise, the distance including the full pixel extent is used. For example, a 1d signal of length 5 is considered to have length 4 when
grid_modeis False, but length 5 whengrid_modeis True. See the following visual illustration:| pixel 1 | pixel 2 | pixel 3 | pixel 4 | pixel 5 | |<-------------------------------------->| vs. |<----------------------------------------------->|
The starting point of the arrow in the diagram above corresponds to coordinate location 0 in each mode.
Returns
zoom: ndarrayThe zoomed input.
Notes
For complex-valued input, this function zooms the real and imaginary components independently.
Examples
from scipy import ndimage, datasets import matplotlib.pyplot as plt✓
fig = plt.figure() ax1 = fig.add_subplot(121) # left side ax2 = fig.add_subplot(122) # right side ascent = datasets.ascent() result = ndimage.zoom(ascent, 3.0)✓
ax1.imshow(ascent, vmin=0, vmax=255) ax2.imshow(result, vmin=0, vmax=255)✗
<matplotlib.image.AxesImage object at 0x7f3f69119e50>
plt.show()
✓
print(ascent.shape)
✓(512, 512)
print(result.shape)
✓(1536, 1536)
Aliases
scipy.ndimage.zoom