在 NumPy 中返回给定列表的尾数和指数对
要返回给定列表的尾数和指数对,请在 Python NumPy 中使用 **numpy.frexp()** 方法。输出是一个存储结果的位置。如果提供,它必须具有输入广播到的形状。如果不提供或为 None,则返回一个新分配的数组。元组(仅作为关键字参数可能)的长度必须等于输出的数量。
条件在输入上进行广播。在条件为 True 的位置,out 数组将设置为 ufunc 结果。在其他地方,out 数组将保留其原始值。请注意,如果通过默认的 out=None 创建了一个未初始化的 out 数组,则其中条件为 False 的位置将保持未初始化。
步骤
首先,导入所需的库 -
import numpy as np
创建一个列表 -
myList = [15.9, 39.2, 166.8, -14.8, 78,6, -19.8]
显示数组 -
print("List...
", myList)列表的长度 -
print("
List length...
", len(myList))
列表的类型 -
print("
List type...
", type(myList))要返回给定列表的尾数和指数对,请在 Python NumPy 中使用 numpy.frexp() 方法 -
print("
Result...
",np.frexp(myList))
示例
import numpy as np
# Create a list
myList = [15.9, 39.2, 166.8, -14.8, 78,6, -19.8]
# Display the list
print("List...
", myList)
# Length of the list
print("
List length...
", len(myList))
# Type of the list
print("
List type...
", type(myList))
# To return mantissa and exponent as a pair of a given list, use the numpy.frexp() method in Python Numpy
print("
Result...
",np.frexp(myList))输出
List... [15.9, 39.2, 166.8, -14.8, 78, 6, -19.8] List length... 7 List type... <class 'list'> Result... (array([ 0.99375 , 0.6125 , 0.6515625, -0.925 , 0.609375 , 0.75 , -0.61875 ]), array([4, 6, 8, 4, 7, 3, 5], dtype=int32))
广告
数据结构
网络
关系型数据库管理系统 (RDBMS)
操作系统
Java
iOS
HTML
CSS
Android
Python
C 语言编程
C++
C#
MongoDB
MySQL
Javascript
PHP