numpy 1.22.4 Pypi GitHub Homepage
Other Docs
ParametersReturnsBackRef
ptp(a, axis=None, out=None, keepdims=<no value>)

The name of the function comes from the acronym for 'peak to peak'.

warning

:None:None:`ptp` preserves the data type of the array. This means the return value for an input of signed integers with n bits (e.g. :None:None:`np.int8`, :None:None:`np.int16`, etc) is also a signed integer with n bits. In that case, peak-to-peak values greater than 2**(n-1)-1 will be returned as negative values. An example with a work-around is shown below.

Parameters

a : array_like

Input values.

axis : None or int or tuple of ints, optional

Axis along which to find the peaks. By default, flatten the array. :None:None:`axis` may be negative, in which case it counts from the last to the first axis.

versionadded

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_like

Alternative 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, optional

If 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 :None:None:`keepdims` will not be passed through to the ptp method of sub-classes of ndarray , however any non-default value will be. If the sub-class' method does not implement :None:None:`keepdims` any exceptions will be raised.

Returns

ptp : ndarray

A new array holding the result, unless :None:None:`out` was specified, in which case a reference to :None:None:`out` is returned.

Range of values (maximum - minimum) along an axis.

Examples

>>> x = np.array([[4, 9, 2, 10],
...  [6, 9, 7, 12]])
>>> np.ptp(x, axis=1)
array([8, 6])
>>> np.ptp(x, axis=0)
array([2, 0, 5, 2])
>>> np.ptp(x)
10

This example shows that a negative value can be returned when the input is an array of signed integers.

>>> y = np.array([[1, 127],
...  [0, 127],
...  [-1, 127],
...  [-2, 127]], dtype=np.int8)
... np.ptp(y, axis=1) array([ 126, 127, -128, -127], dtype=int8)

A work-around is to use the :None:None:`view()` method to view the result as unsigned integers with the same bit width:

>>> np.ptp(y, axis=1).view(np.uint8)
array([126, 127, 128, 129], dtype=uint8)
See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

dask.array.routines.ptp numpy.matrixlib.defmatrix.matrix.ptp numpy.ptp numpy.histogram_bin_edges

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


GitHub : /numpy/core/fromnumeric.py#2576
type: <class 'function'>
Commit: