numpy 1.22.4 Pypi GitHub Homepage
Other Docs
ParametersReturns
ptp(obj, axis=None, out=None, fill_value=None, keepdims=<no value>)
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

axis : {None, int}, optional

Axis along which to find the peaks. If None (default) the flattened array is used.

out : {None, array_like}, optional

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 will be cast if necessary.

fill_value : scalar or None, optional

Value used to fill in the masked values.

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 array.

Returns

ptp : ndarray.

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

Return (maximum - minimum) along the given dimension (i.e. peak-to-peak value).

Examples

This example is valid syntax, but we were not able to check execution
>>> x = np.ma.MaskedArray([[4, 9, 2, 10],
...  [6, 9, 7, 12]])
This example is valid syntax, but we were not able to check execution
>>> x.ptp(axis=1)
masked_array(data=[8, 6],
             mask=False,
       fill_value=999999)
This example is valid syntax, but we were not able to check execution
>>> x.ptp(axis=0)
masked_array(data=[2, 0, 5, 2],
             mask=False,
       fill_value=999999)
This example is valid syntax, but we were not able to check execution
>>> x.ptp()
10

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

This example is valid syntax, but we were not able to check execution
>>> y = np.ma.MaskedArray([[1, 127],
...  [0, 127],
...  [-1, 127],
...  [-2, 127]], dtype=np.int8)
... y.ptp(axis=1) masked_array(data=[ 126, 127, -128, -127], mask=False, fill_value=999999, 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:

This example is valid syntax, but we were not able to check execution
>>> y.ptp(axis=1).view(np.uint8)
masked_array(data=[126, 127, 128, 129],
             mask=False,
       fill_value=999999,
            dtype=uint8)
See :

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/ma/core.py#6725
type: <class 'function'>
Commit: