w3resource

NumPy Data type: min_scalar_type() function

numpy.min_scalar_type() function

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.

Version: 1.15.0

Syntax:

numpy.min_scalar_type(a)

Parameter:

Name Description Required /
Optional
a The value whose minimal data type is to be found. Required

Return value:

out : dtype - The minimal data type.

Example: numpy.min_sclar_type() function

>>> import numpy as np
>>> np.min_scalar_type(160)
dtype('uint8')
>>> np.min_scalar_type(-250)
dtype('int16')

Example: numpy.min_sclar_type() function

>>> import numpy as np
>>> np.min_scalar_type(5.5)
dtype('float16')
>>> np.min_scalar_type(2e5)
dtype('float32')
>>> np.min_scalar_type(np.arange(6,dtype='f8'))
dtype('float64')

Python - NumPy Code Editor:

Previous: promote_types()
Next: result_type()



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://w3resource.com/numpy/data-type-routines/min_scalar_type.php