MCPcopy
hub / github.com/numpy/numpy / ptp

Method ptp

numpy/ma/core.py:6079–6166  ·  view source on GitHub ↗

Return (maximum - minimum) along the given dimension (i.e. peak-to-peak value). .. warning:: `ptp` preserves the data type of the array. This means the return value for an input of signed integers with n bits (e.g. `np.int8`, `np.int16`,

(self, axis=None, out=None, fill_value=None, keepdims=False)

Source from the content-addressed store, hash-verified

6077 return out
6078
6079 def ptp(self, axis=None, out=None, fill_value=None, keepdims=False):
6080 """
6081 Return (maximum - minimum) along the given dimension
6082 (i.e. peak-to-peak value).
6083
6084 .. warning::
6085 `ptp` preserves the data type of the array. This means the
6086 return value for an input of signed integers with n bits
6087 (e.g. `np.int8`, `np.int16`, etc) is also a signed integer
6088 with n bits. In that case, peak-to-peak values greater than
6089 ``2**(n-1)-1`` will be returned as negative values. An example
6090 with a work-around is shown below.
6091
6092 Parameters
6093 ----------
6094 axis : {None, int}, optional
6095 Axis along which to find the peaks. If None (default) the
6096 flattened array is used.
6097 out : {None, array_like}, optional
6098 Alternative output array in which to place the result. It must
6099 have the same shape and buffer length as the expected output
6100 but the type will be cast if necessary.
6101 fill_value : scalar or None, optional
6102 Value used to fill in the masked values.
6103 keepdims : bool, optional
6104 If this is set to True, the axes which are reduced are left
6105 in the result as dimensions with size one. With this option,
6106 the result will broadcast correctly against the array.
6107
6108 Returns
6109 -------
6110 ptp : ndarray.
6111 A new array holding the result, unless ``out`` was
6112 specified, in which case a reference to ``out`` is returned.
6113
6114 Examples
6115 --------
6116 >>> import numpy as np
6117 >>> x = np.ma.MaskedArray([[4, 9, 2, 10],
6118 ... [6, 9, 7, 12]])
6119
6120 >>> x.ptp(axis=1)
6121 masked_array(data=[8, 6],
6122 mask=False,
6123 fill_value=999999)
6124
6125 >>> x.ptp(axis=0)
6126 masked_array(data=[2, 0, 5, 2],
6127 mask=False,
6128 fill_value=999999)
6129
6130 >>> x.ptp()
6131 10
6132
6133 This example shows that a negative value can be returned when
6134 the input is an array of signed integers.
6135
6136 >>> y = np.ma.MaskedArray([[1, 127],

Callers 7

test_ptpMethod · 0.45
test_basicMethod · 0.45
fromnumeric.pyFile · 0.45
ptpFunction · 0.45
test_ptpMethod · 0.45
test_minmax_methodsMethod · 0.45
test_ptpMethod · 0.45

Calls 2

maxMethod · 0.95
minMethod · 0.95

Tested by 5

test_ptpMethod · 0.36
test_basicMethod · 0.36
test_ptpMethod · 0.36
test_minmax_methodsMethod · 0.36
test_ptpMethod · 0.36