NumPy | spacing method
Start your free 7-days trial now!
Numpy's spacing(~)
method returns the difference between the next representable adjacent number.
Parameters
1. a
| array-like
The input array.
2. out
| Numpy array
| optional
Instead of creating a new array, you can place the computed result into the array specified by out.
3. where
| array
of boolean
| optional
Values that are flagged as False will be ignored, that is, their original value will be uninitialized. If you specified the out parameter, the behavior is slightly different - the original value will be kept intact. Since this is a source of confusion for many, check examples below.
Return value
If a
is a scalar, then a scalar is returned. Otherwise, a Numpy array of float is returned.
Examples
Here's an example:
5 + np.spacing(5)
5.000000000000001
Here, the next smallest number that can be represented in Numpy is what is shown in as the output.