w3resource

Numpy Data type: mintypecode() function

numpy.mintypecode() function

The numpy.mintypecode() function returns the character for the minimum-size type to which given types can be safely cast.

The returned type character must represent the smallest size dtype such that an array of the returned type can handle the data from an array of all types in typechars (or if typechars is an array, then its dtype.char).

Version: 1.15.0

Syntax:

numpy.mintypecode(typechars, typeset='GDFgdf', default='d')

Parameter:

Name Description Required /
Optional
typechars : list of str or array_like If a list of strings, each string should represent a dtype. If array_like, the character representation of the array dtype is used.
typeset : str or list of str, The set of characters that the returned character is chosen from. The default set is 'GDFgdf'. optional
default : str, The default character, this is returned if none of the characters in typechars matches a character in typeset. optional

Return value:

typechar : str - The character representing the minimum-size type that was found.

Example-1: numpy.mintypecode() function

>>> import numpy as np
>>> np.mintypecode(['d', 'f', 'S'])
'd'
>>> a = np.array([1.1, 2-3.j])
>>> np.mintypecode(a)
'D'

Example-2: numpy.mintypecode() function

>>> import numpy as np
>>> np.mintypecode('abceh', default='F')
'F'

Python Code Editor:

Previous: sctype2char()
Next: NumPy Home



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/mintypecode.php