flopscope.numpy.min_scalar_type
fnp.min_scalar_type(*args, **kwargs)[flopscope source]
For scalar ``a``, returns the data type with the smallest size and smallest scalar kind which can hold its value. For non-scalar array ``a``, returns the vector's dtype unmodified.
Adapted from NumPy docs np.min_scalar_type
Cost
0
Flopscope Context
Return the minimum scalar type for a value.
For scalar a, returns the data type with the smallest size and smallest scalar kind which can hold its value. For non-scalar array a, returns the vector's dtype unmodified.
Floating point values are not demoted to integers, and complex values are not demoted to floats.
Parameters
- a:scalar or array_like
The value whose minimal data type is to be found.
Returns
- out:dtype
The minimal data type.
See also
Examples
>>> import flopscope.numpy as fnp
>>> flops.min_scalar_type(10)
dtype('uint8')>>> flops.min_scalar_type(-260)
dtype('int16')>>> flops.min_scalar_type(3.1)
dtype('float16')>>> flops.min_scalar_type(1e50)
dtype('float64')>>> flops.min_scalar_type(flops.arange(4,dtype='f8'))
dtype('float64')