返回 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