nlcpy.ptp
- nlcpy.ptp(a, axis=None, out=None, keepdims=<no value>)[ソース]
Range of values (maximum - minimum) along an axis.
The name of the function comes from the acronym for 'peak to peak'.
- Parameters
- aarray_like
Input values.
- axisNone or int or tuple of ints, optional
Axis along which to find the peaks. By default, flatten the array. axis may 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.
- outarray_like
Alternative output array in which to place the result. Must be of the same shape and buffer length as the expected output.
- keepdimsbool, 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 keepdims will not be passed through to the ptp method of sub-classes of n-dimensional_array "ndarray", however any non-default value will be. If the sub-class' method does not implement keepdims any exceptions will be raised.
- Returns
- ptpndarray
A new array holding the result, unless out was specified, in which case a reference to out is returned.
注釈
ptp()
preserves the data type of the array. This means the return value for an input of signed integers with n bits (e.g. nlcpy.int32, nlcpy.int64, 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.制限事項
This function is the wrapper function to utilize
numpy.ptp()
. Calculations during this function perform on only Vector Host(Linux/x86).Examples
>>> import nlcpy as vp >>> x = vp.array([[4, 9, 2, 10], ... [6, 9, 7, 12]]) >>> vp.ptp(x, axis=1) array([8, 6]) >>> vp.ptp(x, axis=0) array([2, 0, 5, 2]) >>> vp.ptp(x) array(10)
This example shows that a negative value can be returned when the input is an array of signed integers.
>>> y = vp.array([[1, 127], [0, 127], [-1, 127], [-2, 127]], dtype=vp.int32) >>> vp.ptp(y, axis=1) array([126, 127, 128, 129], dtype=int32)
A work-around is to use the view() method to view the result as unsigned integers with the same bit width:
>>> vp.ptp(y, axis=1).view(vp.uint32) array([126, 127, 128, 129], dtype=uint32)