返回NumPy中輸入的向下取整值
要返回輸入的向下取整值,請在Python NumPy中使用**numpy.floor()**方法。標量x的向下取整值是最大的整數i,使得i <= x。它通常表示為**$\mathrm{\lfloor X \rfloor}$**。該函式返回x中每個元素的向下取整值。如果x是標量,則這是一個標量。
out是一個將結果儲存其中的位置。如果提供,則其形狀必須與輸入廣播到的形狀相同。如果沒有提供或為None,則返回一個新分配的陣列。元組(只能作為關鍵字引數)的長度必須等於輸出的數量。
步驟
首先,匯入所需的庫:
import numpy as np
要返回輸入的向下取整值,請在Python NumPy中使用numpy.floor()方法。
檢查浮點數的floor():
print("Result? ", np.floor(45.7))
print("
Result? ", np.floor(-487.4))檢查無窮大的floor():
print("
Result? ", np.floor(-np.inf))
檢查NaN和無窮大的floor():
print("
Result? ", np.floor(np.nan))
print("
Result? ", np.floor(np.inf))檢查對數的floor():
print("
Result? ", np.floor(np.log(1)))
print("
Result? ", np.floor(np.log(2)))示例
import numpy as np
# To return the floor of the input, use the numpy.floor() method in Python Numpy
print("Returning the floor value...
")
# Check floor() for float
print("Result? ", np.floor(45.7))
print("
Result? ", np.floor(-487.4))
# Check floor() for inf
print("
Result? ", np.floor(-np.inf))
# Check floor() for nan and inf
print("
Result? ", np.floor(np.nan))
print("
Result? ", np.floor(np.inf))
# Check floor() for log
print("
Result? ", np.floor(np.log(1)))
print("
Result? ", np.floor(np.log(2)))輸出
Returning the floor value... Result? 45.0 Result? -488.0 Result? -inf Result? nan Result? inf Result? 0.0 Result? 0.0
廣告
資料結構
網路
關係型資料庫管理系統 (RDBMS)
作業系統
Java
iOS
HTML
CSS
Android
Python
C語言程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP