
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Find the minimal data type of a scalar value in Python
The numpy.min_scalar() method finds the minimal data type. The 1st parameter is the value whose minimal data type is to be found. For scalar, returns the data type with the smallest size and smallest scalar kind which can hold its value. For non-scalar array, returns the vector’s dtype unmodified. Floating point values are not demoted to integers, and complex values are not demoted to floats.
Steps
At first, import the required library −
import numpy as np
The numpy.min_scalar() method finds the minimal data type −
print("Using the min_scalar() method in Numpy\n") print("Result...",np.min_scalar_type(55)) print("Result...",np.min_scalar_type(38.9)) print("Result...",np.min_scalar_type(-78)) print("Result...",np.min_scalar_type(479)) print("Result...",np.min_scalar_type(2e100)) print("Result...",np.min_scalar_type(-45.8)) print("Result...",np.min_scalar_type(6.5e100))
Example
# For scalar, returns the data type with the smallest size and smallest scalar kind which can hold its value. # For non-scalar array, returns the vector’s dtype unmodified. # Floating point values are not demoted to integers, and complex values are not demoted to floats. import numpy as np # The numpy.min_scalar() method finds the minimal data type. # The 1st parameter is the value whose minimal data type is to be found. print("Using the min_scalar() method in Numpy\n") print("Result...",np.min_scalar_type(55)) print("Result...",np.min_scalar_type(38.9)) print("Result...",np.min_scalar_type(-78)) print("Result...",np.min_scalar_type(479)) print("Result...",np.min_scalar_type(2e100)) print("Result...",np.min_scalar_type(-45.8)) print("Result...",np.min_scalar_type(6.5e100))
Output
Using the min_scalar() method in Numpy Result... uint8 Result... float16 Result... int8 Result... uint16 Result... float64 Result... float16 Result... float64
- Related Articles
- Find the minimal data type of an array-like in Python
- Determine whether the given object represents a scalar data-type in Python
- Program to Find Out the Minimal Submatrices in Python
- Return a scalar type which is common to the input arrays in Python
- Return True if cast between scalar and data type can occur according to the casting rule in Python
- Return True if cast between array scalar and data type can occur according to the casting rule in Python
- Return the scalar dtype or NumPy equivalent of Python type of an object
- Return the scalar type of highest precision of the same kind as the input in Python
- XOR every element of a masked array by a given scalar value in Python
- XOR a given scalar value with every element of a masked array in Python
- AND every element of a masked array by a given scalar value in Python
- AND a given scalar value with every element of a masked array in Python
- OR every element of a masked array by a given scalar value in Python
- OR a given scalar value with every element of a masked array in Python
- Return the data type with the smallest size and scalar kind to which both the given types be safely cast in Python

Advertisements