numpy.mintypecode()函数– Python
numpy.mintypecode()
函数返回可以安全地将给定类型转换为的最小大小类型的字符。
Syntax : numpy.mintypecode(typechars, typeset = ‘GDFgdf’, default = ‘d’)
Parameters :
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, optional] The set of characters that the returned character is chosen from. The default set is ‘GDFgdf’.
default : [str, optional] The default character, this is returned if none of the characters in typechars matches a character in typeset.
Return : [str] The character representing the minimum-size type that was found.
代码#1:
# Python program explaining
# numpy.mintypecode() function
# importing numpy as geek
import numpy as geek
gfg = geek.mintypecode(['d', 'f', 'S'])
print (gfg)
输出 :
d
代码#2:
# Python program explaining
# numpy.mintypecode() function
# importing numpy as geek
import numpy as geek
x = geek.array([1.1, 2-1.j])
gfg = geek.mintypecode(x)
print (gfg)
输出 :
D