Lower-bound binning
Convert continuous measurements into lower integer-valued bins.
NumPy · Function
Returns the mathematical floor of input values element-wise: the greatest integer less than or equal to each value. It returns an ndarray for array input and a scalar for scalar input.
np.floor is a universal function that applies the mathematical floor independently to each input element. For every value, it selects the greatest integer that is less than or equal to that value; array input produces an array, while scalar input produces a scalar.
numpy.floor(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True [, signature])| Name | Type | Description |
|---|---|---|
x | array_like | Input data. |
out | ndarray, None, or tuple of ndarray and None, optional | Destination in which the result is stored; may be an ndarray, None, or a tuple of ndarray and None. |
where | array_like of bool, optional | Condition broadcast over the input; where false, the output is not computed. |
casting | {‘no’, ‘equiv’, ‘safe’, ‘same_kind’, ‘unsafe’}, optional | Controls the data-type casting permitted for the operation. |
order | {‘K’, ‘A’, ‘C’, ‘F’}, optional | Controls the memory layout of the result. |
dtype | dtype, optional | Data type of the returned result. |
subok | bool, optional | If true, subclasses of ndarray are passed through. |
signature | str or tuple of ints, optional | Generalized ufunc signature, when applicable. |
ndarray or scalar: the floor of each element in x; a scalar if x is a scalar.
out argument can store results in a supplied destination.import numpy as np
values = np.array([-1.7, -0.2, 0.2, 1.7])
print(np.floor(values))
# [-2. -1. 0. 1.]Applies floor element-wise, including rounding negative nonintegers toward smaller values.
Convert continuous measurements into lower integer-valued bins.
Apply a mathematical lower bound to every value in an ndarray without writing an explicit loop.
Reuse an existing destination array or restrict updates with ufunc output controls.
np.floor compute?np.floor returns the floor of its input element-wise. For each scalar, that is the largest integer less than or equal to the value.
Follow-up: How does it behave for a scalar input? It returns a scalar rather than a one-element array.
The function accepts array-like input and returns the floor of every element. An array input yields an ndarray, whereas a scalar input yields a scalar.
Follow-up: What happens with negative values? A value such as -0.2 becomes -1, because -1 is the greatest integer no larger than -0.2.
As a ufunc, np.floor supports an optional out destination and a where mask in addition to the input. These enable selective computation and storage into a supplied array.
Follow-up: Why use where with out? Unselected positions can retain their preexisting destination values instead of being recalculated.
numpy.ceilnumpy.truncnumpy.rint