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

round has 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. out is 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. out is never supported for JAX because JAX arrays are immutable.

For alternative backends, this is essentially an alias of xp.round and thus behaves differently from scipy.special.round with respect to input dtype.

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.])