
- 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 an array-like 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. 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(np.arange(4,dtype='f8'))) print("Result...",np.min_scalar_type(np.arange(38.9, dtype = 'f8'))) print("Result...",np.min_scalar_type(np.array(6.5e100, np.float64))) print("Result...",np.min_scalar_type(np.array(280, 'i1'))) print("Result...",np.min_scalar_type(np.array(80, 'u1'))) print("Result...",np.min_scalar_type(np.array(300.7, np.float32))) print("Result...",np.min_scalar_type(np.array(120.6, np.float64))) print("Result...",np.min_scalar_type(np.array(7.2e100, np.float32))) print("Result...",np.min_scalar_type(np.array(6.5e100, np.float64)))
Example
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(np.arange(4,dtype='f8'))) print("Result...",np.min_scalar_type(np.arange(38.9, dtype = 'f8'))) print("Result...",np.min_scalar_type(np.array(6.5e100, np.float64))) print("Result...",np.min_scalar_type(np.array(280, 'i1'))) print("Result...",np.min_scalar_type(np.array(80, 'u1'))) print("Result...",np.min_scalar_type(np.array(300.7, np.float32))) print("Result...",np.min_scalar_type(np.array(120.6, np.float64))) print("Result...",np.min_scalar_type(np.array(7.2e100, np.float32))) print("Result...",np.min_scalar_type(np.array(6.5e100, np.float64)))
Output
Using the min_scalar() method in Numpy Result... float64 Result... float64 Result... float64 Result... uint8 Result... uint8 Result... float16 Result... float16 Result... float16 Result... float64
- Related Articles
- Find the minimal data type of a scalar value in Python
- Change data type of given numpy array in Python
- Program to Find Out the Minimal Submatrices in Python
- Python Pandas - Construct an IntervalArray from an array-like of tuples
- Return a map representing the frequency of each data type in an array in JavaScript
- Number Data Type in Python
- String Data Type in Python
- List Data Type in Python
- Tuple Data Type in Python
- Dictionary Data Type in Python
- Data Type Conversion in Python
- Change data type of given numpy array
- Python - Return an array representing the data in the Pandas Index
- Return a new array of given shape and type, filled with array-like in Numpy
- Determine the type of an image in Python?

Advertisements