swectral.round_digit#
- swectral.round_digit(value, sig_digit, mode='round')[source]#
Round values or values in arraylike to specified significant digits.
- Parameters:
- value
realnumberor array_like Real number or array-like of real numbers.
Supported array-like types: tuple, list,
numpy.ndarray,pandas.Series,torch.Tensor.- sig_digit
int Number of significant digits, must be at least 1.
- mode
str,optional Rounding mode, choose between:
"round""ceil""floor"
The default is
"round".
- value
- Returns:
- result
floatortupleorlistornumpy.ndarrayorpandas.Seriesorpandas.DataFrameortorch.Tensor Rounded value or array-like of values.
If the input is a number, returns a float. If the input is array-like, returns an object of the same type containing rounded values.
- result
- Return type:
Union[float,tuple,list,ndarray,Series,DataFrame,Tensor]
Examples
Round numbers:
>>> round_digit(130.33, 2) >>> round_digit(0.323233, 2, 'ceil') >>> round_digit(138323, 2, 'floor')
Round array-like of numbers:
>>> round_digit([[1111, 2222], [9999, 7777]], 2)