在 NumPy 中返回特定元組元素的尾數和指數作為一對
要返回給定元組的一對尾數和指數,請在 Python NumPy 中使用 **numpy.frexp()** 方法中的索引值。
輸出是儲存結果的位置。如果提供,它必須具有輸入廣播到的形狀。如果未提供或為 None,則返回一個新分配的陣列。元組(僅作為關鍵字引數可能)的長度必須等於輸出的數量。
條件在輸入上廣播。在條件為 True 的位置,out 陣列將設定為 ufunc 結果。在其他地方,out 陣列將保留其原始值。請注意,如果透過預設的 out=None 建立了一個未初始化的 out 陣列,則其中條件為 False 的位置將保持未初始化。
NumPy 提供了全面的數學函式、隨機數生成器、線性代數例程、傅立葉變換等等。它支援各種硬體和計算平臺,並且與分散式、GPU 和稀疏陣列庫配合良好。
步驟
首先,匯入所需的庫 -
import numpy as np
建立一個元組 -
myTuple = (27.3, 12.9, 166.8, -14.8, 78,6, -19.8)
顯示元組 -
print("Tuple...
", myTuple)元組的長度 -
print("
Tuple length...
", len(myTuple))
元組的型別 -
print("
Tuple type...
", type(myTuple))返回給定元組的一對尾數和指數 -
print("
Return mantissa and exponent as a pair of a given tuple...
",np.frexp(myTuple))
要返回給定元組的一對尾數和指數,請使用 numpy.frexp() 方法中的索引值 -
print("
Result (specific element)...
",np.frexp(myTuple[5]))示例
import numpy as np
# Create a tuple
myTuple = (27.3, 12.9, 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))
# Return mantissa and exponent as a pair of a given tuple
print("
Return mantissa and exponent as a pair of a given tuple...
",np.frexp(myTuple))
# To return mantissa and exponent as a pair of a given tuple, use the index value in the numpy.frexp() method in Python Numpy
print("
Result (specific element)...
",np.frexp(myTuple[5]))輸出
Tuple... (27.3, 12.9, 166.8, -14.8, 78, 6, -19.8) Tuple length... 7 Tuple type... <class 'tuple'> Return mantissa and exponent as a pair of a given tuple... (array([ 0.853125 , 0.80625 , 0.6515625, -0.925 , 0.609375 , 0.75 , -0.61875 ]), array([5, 4, 8, 4, 7, 3, 5], dtype=int32)) Result (specific element)... (0.75, 3)
廣告
資料結構
網路
關係型資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP