bundles / numpy 2.4.4 / numpy / ma / core / ptp
function
numpy.ma.core:ptp
source: /numpy/ma/core.py :7018
Signature
def ptp ( obj , axis = None , out = None , fill_value = None , keepdims = <no value> ) Summary
Return (maximum - minimum) along the given dimension (i.e. peak-to-peak value).
Extended Summary
Parameters
axis: {None, int}, optionalAxis along which to find the peaks. If None (default) the flattened array is used.
out: {None, array_like}, optionalAlternative output array in which to place the result. It must have the same shape and buffer length as the expected output but the type will be cast if necessary.
fill_value: scalar or None, optionalValue used to fill in the masked values.
keepdims: bool, optionalIf this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the array.
Returns
ptp: ndarray.A new array holding the result, unless
outwas specified, in which case a reference tooutis returned.
Examples
import numpy as np x = np.ma.MaskedArray([[4, 9, 2, 10], [6, 9, 7, 12]])
x.ptp(axis=1)
x.ptp(axis=0)
x.ptp()
This example shows that a negative value can be returned when
the input is an array of signed integers.
y = np.ma.MaskedArray([[1, 127], [0, 127], [-1, 127], [-2, 127]], dtype=np.int8) y.ptp(axis=1)A work-around is to use the `view()` method to view the result as unsigned integers with the same bit width:
y.ptp(axis=1).view(np.uint8)
Aliases
-
numpy.ma.ptp