MCPcopy Create free account
hub / github.com/numpy/numpy / ptp

Method ptp

numpy/ma/core.py:5966–6052  ·  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

5964 return out
5965
5966 def ptp(self, axis=None, out=None, fill_value=None, keepdims=False):
5967 """
5968 Return (maximum - minimum) along the given dimension
5969 (i.e. peak-to-peak value).
5970
5971 .. warning::
5972 `ptp` preserves the data type of the array. This means the
5973 return value for an input of signed integers with n bits
5974 (e.g. `np.int8`, `np.int16`, etc) is also a signed integer
5975 with n bits. In that case, peak-to-peak values greater than
5976 ``2**(n-1)-1`` will be returned as negative values. An example
5977 with a work-around is shown below.
5978
5979 Parameters
5980 ----------
5981 axis : {None, int}, optional
5982 Axis along which to find the peaks. If None (default) the
5983 flattened array is used.
5984 out : {None, array_like}, optional
5985 Alternative output array in which to place the result. It must
5986 have the same shape and buffer length as the expected output
5987 but the type will be cast if necessary.
5988 fill_value : scalar or None, optional
5989 Value used to fill in the masked values.
5990 keepdims : bool, optional
5991 If this is set to True, the axes which are reduced are left
5992 in the result as dimensions with size one. With this option,
5993 the result will broadcast correctly against the array.
5994
5995 Returns
5996 -------
5997 ptp : ndarray.
5998 A new array holding the result, unless ``out`` was
5999 specified, in which case a reference to ``out`` is returned.
6000
6001 Examples
6002 --------
6003 >>> x = np.ma.MaskedArray([[4, 9, 2, 10],
6004 ... [6, 9, 7, 12]])
6005
6006 >>> x.ptp(axis=1)
6007 masked_array(data=[8, 6],
6008 mask=False,
6009 fill_value=999999)
6010
6011 >>> x.ptp(axis=0)
6012 masked_array(data=[2, 0, 5, 2],
6013 mask=False,
6014 fill_value=999999)
6015
6016 >>> x.ptp()
6017 10
6018
6019 This example shows that a negative value can be returned when
6020 the input is an array of signed integers.
6021
6022 >>> y = np.ma.MaskedArray([[1, 127],
6023 ... [0, 127],

Callers 9

test_attributesMethod · 0.45
test_ptpMethod · 0.45
test_basicMethod · 0.45
ndarray_misc.pyFile · 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 6

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