bundles / numpy latest / numpy / ptp
_ArrayFunctionDispatcher
numpy:ptp
source: /dev/numpy/build-install/usr/lib/python3.14/site-packages/numpy/_core/fromnumeric.py :2921
Signature
def ptp ( a , axis = None , out = None , keepdims = <no value> ) Summary
Range of values (maximum - minimum) along an axis.
Extended Summary
The name of the function comes from the acronym for 'peak to peak'.
Parameters
a: array_likeInput values.
axis: None or int or tuple of ints, optionalAxis along which to find the peaks. By default, flatten the array.
axismay be negative, in which case it counts from the last to the first axis. If this is a tuple of ints, a reduction is performed on multiple axes, instead of a single axis or all the axes as before.out: array_likeAlternative output array in which to place the result. It must have the same shape and buffer length as the expected output, but the type of the output values will be cast if necessary.
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 input array.
If the default value is passed, then
keepdimswill not be passed through to the ptp method of sub-classes ofndarray, however any non-default value will be. If the sub-class' method does not implementkeepdimsany exceptions will be raised.
Returns
ptp: ndarray or scalarThe range of a given array -
scalarif array is one-dimensional or a new array holding the result along the given axis
Examples
import numpy as np x = np.array([[4, 9, 2, 10], [6, 9, 7, 12]])✓
np.ptp(x, axis=1)
✓np.ptp(x, axis=0)
✓np.ptp(x)
✗y = np.array([[1, 127], [0, 127], [-1, 127], [-2, 127]], dtype=np.int8) np.ptp(y, axis=1)✓
np.ptp(y, axis=1).view(np.uint8)
✓Aliases
-
numpy.ptp