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