numpy.result_type()函数返回通过将NumPy类型提升规则应用于参数而产生的类型。
NumPy类型提升示例:
假设计算3 * arr(其中arr是32位浮点数的数组),直观地应该得出32位浮点数的输出。如果3是32位整数,则NumPy规则表明它不能无损地转换为32位浮点数,因此结果类型应为64位浮点数。
用法: numpy.result_type(arrays_and_dtypes)
参数:
arrays_and_dtypes:[数组和dtypes的列表]需要结果类型的某些操作的操作数。
返回:[dtype]返回结果类型。
代码1:
# Python program explaining
# numpy.result_type() function
# importing numpy as geek
import numpy as geek
gfg = geek.result_type('f4', 'i8')
print (gfg)
输出:
float64
代码2:
# Python program explaining
# numpy.result_type() function
# importing numpy as geek
import numpy as geek
gfg = geek.result_type(3, geek.arange(7, dtype = 'i1'))
print (gfg)
输出:
int8
相关用法
- Python Wand function()用法及代码示例
- Python now()用法及代码示例
- Python id()用法及代码示例
- Python tell()用法及代码示例
- Python sum()用法及代码示例
- Python str()用法及代码示例
- Python cmp()用法及代码示例
- Python ord()用法及代码示例
- Python dir()用法及代码示例
- Python hex()用法及代码示例
- Python int()用法及代码示例
- Python map()用法及代码示例
- Python oct()用法及代码示例
- Python math.sin()用法及代码示例
- Python bytearray()用法及代码示例
- Python math.tan()用法及代码示例
注:本文由纯净天空筛选整理自sanjoy_62大神的英文原创作品 numpy.result_type() function – Python。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。