python numpy 向下取整,向上取整 np.floor()、np.ceil()

from numpy\core_multiarray_umath.py

np.floor()

def floor(x, *args, **kwargs): # real signature unknown; NOTE: unreliably restored from __doc__ 
    """
    floor(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature, extobj])
    
    Return the floor of the input, element-wise.
    以元素爲單位返回輸入的下限。
    
    The floor of the scalar `x` is the largest integer `i`, such that
    `i <= x`.  It is often denoted as :math:`\lfloor x \rfloor`.
    標量“ x”的下限是最大的整數“ i”,因此“ i <= x”。 它通常表示爲:\ lfloor x \ rfloor`。
    
    Parameters
    ----------
    x : array_like
        Input data.
    out : ndarray, None, or tuple of ndarray and None, optional
        A location into which the result is stored. If provided, it must have
        a shape that the inputs broadcast to. If not provided or None,
        a freshly-allocated array is returned. A tuple (possible only as a
        keyword argument) must have length equal to the number of outputs.
        結果存儲的位置。 如果提供,它必須具有輸入廣播到的形狀。 
        如果未提供或沒有,則返回一個新分配的數組。 
        元組(只能作爲關鍵字參數)的長度必須等於輸出的數量。
        
    where : array_like, optional
        This condition is broadcast over the input. At locations where the
        condition is True, the `out` array will be set to the ufunc result.
        Elsewhere, the `out` array will retain its original value.
        Note that if an uninitialized `out` array is created via the default
        ``out=None``, locations within it where the condition is False will
        remain uninitialized.
        此條件通過輸入廣播。 在條件爲True的位置,將`out`數組設置爲ufunc結果。 
        在其他地方,`out`數組將保留其原始值。 
        請注意,如果通過默認的“ out = None”創建了未初始化的“ out”數組,
        則條件爲False的數組中的位置將保持未初始化狀態。
        
    **kwargs
        For other keyword-only arguments, see the
        :ref:`ufunc docs <ufuncs.kwargs>`.
    
    Returns
    -------
    y : ndarray or scalar
        The floor of each element in `x`.
        This is a scalar if `x` is a scalar.
        x中每個元素的下限。 如果x是標量,則這是標量。
    
    See Also
    --------
    ceil, trunc, rint
    
    Notes
    -----
    Some spreadsheet programs calculate the "floor-towards-zero", in other
    words ``floor(-2.5) == -2``.  NumPy instead uses the definition of
    `floor` where `floor(-2.5) == -3`.
    某些電子表格程序會計算“底數朝零”,而其他單詞``floor(-2.5)== -2''。 
	NumPy改爲使用`floor`其中`floor(-2.5)== -3`
    
    Examples
    --------
    >>> a = np.array([-1.7, -1.5, -0.2, 0.2, 1.5, 1.7, 2.0])
    >>> np.floor(a)
    array([-2., -2., -1.,  0.,  1.,  1.,  2.])
    """
    pass

np.ceil()同理

示例

# -*- coding: utf-8 -*-
"""
@File    : test.py
@Time    : 2020/6/25 11:27
@Author  : Dontla
@Email   : [email protected]
@Software: PyCharm
"""
import numpy as np

print(np.ceil(1.7)) # 2.0

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章