The numpy.spacing()
function in NumPy is used to compute the distance between an input value x
and the nearest adjacent number.
numpy.spacing(x, /, out=None, *, where=True)
The numpy.spacing()
function takes the following parameter values.
x
: This represents the input value whose spacing is to be returned and is a required parameter.out
: This represents the location where the result is stored and is an optional parameter. where
: This is the condition over which the input is being broadcasted. At a given location where this condition is True
, the resulting array will be set to the ufunc
result. Otherwise, the resulting array will retain its original value. This is an optional parameter.**kwargs
: This represents other keyword arguments and is an optional parameter.It returns a scalar value which represents the distance between an input value x
and the nearest adjacent number.
import numpy as np# implementing the numpy.spacing() functionprint(np.spacing(5))
numpy
module.numpy.spacing
function to determine the distance between 5
and the nearest adjacent number. We print the result to the console.