isscalar

erwans3.utils.isscalar(x: Any) bool

Determine if the input is a scalar value.

Check whether x is has a single value. Compare to numpy.isscalar(), this function works with n dimensions and with astropy.units.Quantity

Parameters:

x (Any) – Input value to check for scalar nature.

Returns:

True if x is a scalar value, False otherwise.

Return type:

bool

Notes

This function checks if the input is a scalar, which includes checking if it is a NumPy scalar, a quantity with a shape of () or a numpy array with a single element.

Examples

>>> isscalar(5)
True
>>> isscalar([1, 2, 3])
False
>>> import numpy as np
>>> isscalar(np.array(10))
True
>>> import astropy.units as u
>>> isscalar(u.Quantity(5, 'm'))
True