ceil_divide¶
-
mdtools.numpy_helper_functions.
ceil_divide
(x1, x2, **kwargs)[source]¶ Calculate element-wise ceil division.
Return the smallest integer greater or equal to the division of the inputs. It is equivalent to
-(-x1 // x2)
and can bee regarded as the oppoiste ofnumpy.floor_divide()
.- Parameters
x1 (array_like) – Numerator.
x2 (array_like) – Denominator. If
x1.shape != x2.shape
, they must be broadcastable to a common shape (which becomes the shape of the output).**kwargs (dict, optional) – Additional keyword arguments to parse to
numpy.multiply()
andnumpy.floor_divide()
. See there for possible choices.
- Returns
y – The element-wise ceil division of x1 and x2, formally
y = -(-x1 // x2)
. This is a scalar if both x1 and x2 are scalars.- Return type
See also
numpy.floor_divide()
Element-wise floor division
numpy.ceil()
Element-wise ceiling.
Examples
>>> mdt.nph.ceil_divide(3, 2) 2 >>> np.floor_divide(3, 2) 1 >>> mdt.nph.ceil_divide(3.5, 2) 2.0 >>> np.floor_divide(3.5, 2) 1.0
>>> mdt.nph.ceil_divide(np.arange(3, 6), np.arange(1, 4)) array([3, 2, 2]) >>> np.floor_divide(np.arange(3, 6), np.arange(1, 4)) array([3, 2, 1])
>>> result = np.zeros(3, dtype=int) >>> mask = np.array([True, True, False]) >>> mdt.nph.ceil_divide([5, 5, 5], [2, 3, 3], out=result, where=mask) array([3, 2, 0])