Use scipy.ndimage.rotate to rotate an image array by an angle in degrees. A basic call is ndimage.rotate(image, angle=45, reshape=True); choose the output shape, rotation axes, interpolation order, and edge handling to suit your data.
Basic rotation with SciPy
Import ndimage and pass it an image array and the angle in degrees:
As an Amazon Associate I earn from qualifying purchases.
from scipy import ndimage
rotated = ndimage.rotate(image, angle=45, reshape=True)
The function rotates the array in the plane defined by axes, using spline interpolation of the requested order. The current SciPy v1.18.0 API documents this function and its defaults in the official rotate reference.
Quick wins for a faster PC:
Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Clear out junk files and repair common Windows errorsFree Scan →Scan for outdated or missing drivers - takes under a minuteDriver Scan →Choose whether to keep the original dimensions
With reshape=True (the default), SciPy adjusts the output dimensions to contain the rotated input. With reshape=False, the output retains the input shape, so rotated corners that fall outside those bounds can be cropped.
#1 Best Overall
from scipy import ndimage, datasets
img = datasets.ascent()
fixed = ndimage.rotate(img, 45, reshape=False)
expanded = ndimage.rotate(img, 45, reshape=True)
In SciPy’s documented example, the input shape is (512, 512); the fixed-shape result is (512, 512), while the expanded result is (724, 724). These are the reference example’s values. Expanded output may have fill around the rotated image, depending on the boundary mode.
Set the rotation plane with axes
axes is a pair of integer array axes that defines the plane of rotation. Its default is (1, 0), which selects both dimensions of a conventional two-dimensional image. For an array with more dimensions—such as a multichannel image or a volume—specify the pair explicitly so the intended dimensions rotate.
# Example only: choose the two axes that represent the image plane
rotated = ndimage.rotate(image, 30, axes=(1, 0))
The correct axis pair depends on how the array is laid out; do not assume that a rotation will treat a channel dimension as channels rather than as a spatial axis.
Do these 3 things before closing this tab:
1Repair Windows errors before they cause bigger problems2Fix the driver behind crashes, sound loss and screen glitches3Clear out junk files and repair common Windows errorsChoose interpolation order for the data
The order parameter selects spline interpolation order from 0 through 5. The default is order=3, cubic spline interpolation. A different order changes how values between input samples are calculated; no single order is best for every image or measurement.
Rank #3
- Use the default when cubic spline interpolation is appropriate for your task.
- Consider order 0 when you need to avoid creating interpolated intermediate values, as can matter for masks or label arrays.
- For continuous-valued image data, choose an order based on the desired interpolation behavior and inspect the result for your application.
For order > 1, the default prefilter=True applies spline prefiltering and creates a temporary float64 array. Setting prefilter=False on data that has not already been spline-filtered can slightly blur the result; it is useful when the input has already been spline-filtered and you want to avoid filtering it again.
Control what appears beyond the image edges
The default is mode='constant' with cval=0.0. Samples outside the input boundary use that constant, and interpolation is not performed beyond the input edge. For ordinary imagery this can create a zero-valued border; for masks, labels, or measurements, choose edge handling and fill values deliberately.
Rank #4
| Mode | Boundary behavior |
|---|---|
reflect / grid-mirror |
Reflects about the edge of the last pixel; grid-mirror is a synonym for reflect. |
constant |
Uses cval outside the input and does not interpolate beyond the input edge. |
grid-constant |
Uses constant extension and interpolates outside the input extent. |
nearest |
Repeats the last pixel beyond the boundary. |
mirror |
Reflects about the center of the last pixel. |
grid-wrap |
Wraps to the opposite edge. |
wrap |
Wraps with overlapping endpoints, so the selected sample at the overlap is ambiguous. |
For example, set a nonzero constant fill explicitly when that is the intended border behavior:
rotated = ndimage.rotate(image, 30, reshape=True, mode="constant", cval=255)
The value 255 is only an example; choose a value appropriate to the array’s data and dtype.
Best Value
Other parameters and data types
The full SciPy v1.18.0 signature is scipy.ndimage.rotate(input, angle, axes=(1, 0), reshape=True, output=None, order=3, mode='constant', cval=0.0, prefilter=True). input is array-like. You can provide output as an array to receive the result or as a dtype; otherwise, SciPy creates an output array with the input’s dtype.
Complex-valued inputs are handled by rotating their real and imaginary components independently. The same API page describes experimental Python Array API Standard support for selected backends and device combinations, including NumPy on CPU, CuPy on GPU, PyTorch on CPU, JAX on CPU without JIT, and Dask on CPU (which computes the graph). This support is experimental and version-sensitive; check the version-specific API reference before relying on a backend.
When rotate is not the right operation
ndimage.rotate is the direct choice for a fixed-angle rotation within one plane. If you need a custom output-to-input coordinate mapping or a more general affine operation, SciPy’s ndimage reference index also lists geometric_transform, map_coordinates, and affine_transform. Consult the individual function references for their specific behavior.
The Tool Desk
Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




