scipy.special.round#
- scipy.special.round(x, out=None) = <wrapped_ufunc 'round'>#
Round to the nearest integer.
Returns the nearest integer to x. If x ends in 0.5 exactly, the nearest even integer is chosen.
- Parameters:
- xarray_like
Real valued input.
- outndarray, optional
Optional output array for the function results.
- Returns:
- scalar or ndarray
The nearest integers to the elements of x. The result is of floating type, not integer type.
Notes
Array API Standard Support
roundhas support for Python Array API Standard compatible backends in addition to NumPy. The following combinations of backend and device (or other capability) are supported.Library
CPU
GPU
NumPy
✅
n/a
CuPy
n/a
✅
PyTorch
✅
✅
JAX
✅
✅
Dask
✅
n/a
For the NumPy backend, this function supports all NumPy ufunc keyword arguments. Other backends may support
out, but typically none of the other ufunc kwargs.outis typically supported for CuPy and PyTorch, but not currently in cases where SciPy relies on a generic Array API implementation or, for PyTorch on CPU, falls back to the NumPy backend.outis never supported for JAX because JAX arrays are immutable.For alternative backends, this is essentially an alias of
xp.roundand thus behaves differently fromscipy.special.roundwith respect to inputdtype.See Array API coverage for more information.
Examples
>>> import scipy.special as sc
It rounds to even.
>>> sc.round([0.5, 1.5]) array([0., 2.])