返回给定 NumPy 元组的尾数和指数对
要将尾数和指数作为给定元组的一对返回,请在 Python NumPy 中使用 **numpy.frexp()** 方法。输出是结果存储到的位置。如果提供,则其形状必须与输入广播到的形状相同。如果没有提供或为 None,则返回一个新分配的数组。元组(仅可能作为关键字参数)的长度必须等于输出的数量。
NumPy 提供了全面的数学函数、随机数生成器、线性代数例程、傅里叶变换等等。它支持各种硬件和计算平台,并且与分布式、GPU 和稀疏数组库配合良好。
步骤
首先,导入所需的库:
import numpy as np
创建一个元组:
myTuple = (37.2, 39.2, 166.8, -14.8, 78,6, -19.8)
显示数组:
print("Tuple...
", myTuple)元组的长度:
print("
Tuple length...
", len(myTuple))
元组的类型:
print("
Tuple type...
", type(myTuple))要将尾数和指数作为给定元组的一对返回,请在 Python NumPy 中使用 numpy.frexp() 方法:
print("
Result...
",np.frexp(myTuple))示例
import numpy as np
# Create a tuple
myTuple = (37.2, 39.2, 166.8, -14.8, 78,6, -19.8)
# Display the tuple
print("Tuple...
", myTuple)
# Length of the tuple
print("
Tuple length...
", len(myTuple))
# Type of the tuple
print("
Tuple type...
", type(myTuple))
# To return mantissa and exponent as a pair of a given tuple, use the numpy.frexp() method in Python Numpy
print("
Result...
",np.frexp(myTuple))输出
Tuple... (37.2, 39.2, 166.8, -14.8, 78, 6, -19.8) Tuple length... 7 Tuple type... <class 'tuple'> Result... (array([ 0.58125 , 0.6125 , 0.6515625, -0.925 , 0.609375 , 0.75 , -0.61875 ]), array([6, 6, 8, 4, 7, 3, 5], dtype=int32))
广告
数据结构
网络
关系数据库管理系统 (RDBMS)
操作系统
Java
iOS
HTML
CSS
Android
Python
C语言编程
C++
C#
MongoDB
MySQL
Javascript
PHP