Function reference

Bottleneck provides the following functions:

NumPy/SciPy median, nanmedian, rankdata, ss, nansum, nanmin, nanmax, nanmean, nanstd, nanargmin, nanargmax
Functions nanrankdata, nanvar, partsort, argpartsort
Moving window move_sum, move_nansum, move_mean, move_nanmean, move_median, move_std, move_nanstd, move_min, move_nanmin, move_max, move_nanmax

NumPy/SciPy

Fast replacements for NumPy and SciPy functions.


bottleneck.median(arr, axis=None)

Median of array elements along given axis.

Parameters :

arr : array_like

Input array. If arr is not an array, a conversion is attempted.

axis : {int, None}, optional

Axis along which the median is computed. The default (axis=None) is to compute the median of the flattened array.

Returns :

y : ndarray

An array with the same shape as arr, except that the specified axis has been removed. If arr is a 0d array, or if axis is None, a scalar is returned. float64 return values are used for integer inputs.

See also

bottleneck.nanmedian
Median along specified axis ignoring NaNs.

Notes

This function returns the same output as NumPy’s median except when the input contains NaN.

Examples

>>> a = np.array([[10, 7, 4], [3, 2, 1]])
>>> a
array([[10,  7,  4],
       [ 3,  2,  1]])
>>> bn.median(a)
3.5
>>> bn.median(a, axis=0)
array([ 6.5,  4.5,  2.5])
>>> bn.median(a, axis=1)
array([ 7.,  2.])

bottleneck.nanmedian(arr, axis=None)

Median of array elements along given axis ignoring NaNs.

Parameters :

arr : array_like

Input array. If arr is not an array, a conversion is attempted.

axis : {int, None}, optional

Axis along which the median is computed. The default (axis=None) is to compute the median of the flattened array.

Returns :

y : ndarray

An array with the same shape as arr, except that the specified axis has been removed. If arr is a 0d array, or if axis is None, a scalar is returned. float64 return values are used for integer inputs.

See also

bottleneck.median
Median along specified axis.

Examples

>>> a = np.array([[np.nan, 7, 4], [3, 2, 1]])
>>> a 
array([[ nan,   7.,   4.],
       [  3.,   2.,   1.]])
>>> bn.nanmedian(a)
3.0
>> bn.nanmedian(a, axis=0)
array([ 3. ,  4.5,  2.5])
>> bn.nanmedian(a, axis=1)
array([ 5.5,  2. ])

bottleneck.rankdata(arr, axis=None)

Ranks the data, dealing with ties appropriately.

Equal values are assigned a rank that is the average of the ranks that would have been otherwise assigned to all of the values within that set. Ranks begin at 1, not 0.

Parameters :

arr : array_like

Input array. If arr is not an array, a conversion is attempted.

axis : {int, None}, optional

Axis along which the elements of the array are ranked. The default (axis=None) is to rank the elements of the flattened array.

Returns :

y : ndarray

An array with the same shape as arr. The dtype is ‘float64’.

See also

bottleneck.nanrankdata
Ranks the data dealing with ties and NaNs.

Examples

>>> bn.rankdata([0, 2, 2, 3])
array([ 1. ,  2.5,  2.5,  4. ])
>>> bn.rankdata([[0, 2], [2, 3]])
array([ 1. ,  2.5,  2.5,  4. ])
>>> bn.rankdata([[0, 2], [2, 3]], axis=0)     
array([[ 1.,  1.],
       [ 2.,  2.]])
>>> bn.rankdata([[0, 2], [2, 3]], axis=1)
array([[ 1.,  2.],
       [ 1.,  2.]])

bottleneck.ss(arr, axis=0)

Sum of the square of each element along specified axis.

Parameters :

arr : array_like

Array whose sum of squares is desired. If arr is not an array, a conversion is attempted.

axis : {int, None}, optional

Axis along which the sum if squared is computed. The default (axis=0) is to sum the squares along the first dimension.

Returns :

y : ndarray

The sum of a**2 along the given axis.

Examples

>>> a = np.array([1., 2., 5.])
>>> bn.ss(a)
30.0

And calculating along an axis:

>>> b = np.array([[1., 2., 5.], [2., 5., 6.]])
>>> bn.ss(b, axis=1)
array([ 30., 65.])

bottleneck.nansum(arr, axis=None)

Sum of array elements along given axis ignoring NaNs.

When the input has an integer type with less precision than the default platform integer, the default platform integer is used for the accumulator and return values.

Parameters :

arr : array_like

Array containing numbers whose sum is desired. If arr is not an array, a conversion is attempted.

axis : {int, None}, optional

Axis along which the sum is computed. The default (axis=None) is to compute the sum of the flattened array.

Returns :

y : ndarray

An array with the same shape as arr, with the specified axis removed. If arr is a 0-d array, or if axis is None, a scalar is returned.

Notes

No error is raised on overflow.

If positive or negative infinity are present the result is positive or negative infinity. But if both positive and negative infinity are present, the result is Not A Number (NaN).

Examples

>>> bn.nansum(1)
1
>>> bn.nansum([1])
1
>>> bn.nansum([1, np.nan])
1.0
>>> a = np.array([[1, 1], [1, np.nan]])
>>> bn.nansum(a)
3.0
>>> bn.nansum(a, axis=0)
array([ 2.,  1.])

When positive infinity and negative infinity are present:

>>> bn.nansum([1, np.nan, np.inf])
inf
>>> bn.nansum([1, np.nan, np.NINF])
-inf
>>> bn.nansum([1, np.nan, np.inf, np.NINF])
nan

bottleneck.nanmin(arr, axis=None)

Minimum values along specified axis, ignoring NaNs.

Parameters :

arr : array_like

Input array. If arr is not an array, a conversion is attempted.

axis : {int, None}, optional

Axis along which the minimum is computed. The default (axis=None) is to compute the minimum of the flattened array.

Returns :

y : ndarray

An array with the same shape as arr, with the specified axis removed. If arr is a 0-d array, or if axis is None, a scalar is returned.

See also

bottleneck.nanmax
Maximum along specified axis, ignoring NaNs.
bottleneck.nanargmin
Indices of minimum values along axis, ignoring NaNs.

Examples

>>> bn.nanmin(1)
1
>>> bn.nanmin([1])
1
>>> bn.nanmin([1, np.nan])
1.0
>>> a = np.array([[1, 4], [1, np.nan]])
>>> bn.nanmin(a)
1.0
>>> bn.nanmin(a, axis=0)
array([ 1.,  4.])

bottleneck.nanmax(arr, axis=None)

Maximum values along specified axis, ignoring NaNs.

Parameters :

arr : array_like

Input array. If arr is not an array, a conversion is attempted.

axis : {int, None}, optional

Axis along which the maximum is computed. The default (axis=None) is to compute the maximum of the flattened array.

Returns :

y : ndarray

An array with the same shape as arr, with the specified axis removed. If arr is a 0-d array, or if axis is None, a scalar is returned.

See also

bottleneck.nanmin
Minimum along specified axis, ignoring NaNs.
bottleneck.nanargmax
Indices of maximum values along axis, ignoring NaNs.

Examples

>>> bn.nanmax(1)
1
>>> bn.nanmax([1])
1
>>> bn.nanmax([1, np.nan])
1.0
>>> a = np.array([[1, 4], [1, np.nan]])
>>> bn.nanmax(a)
4.0
>>> bn.nanmax(a, axis=0)
array([ 1.,  4.])

bottleneck.nanmean(arr, axis=None)

Mean of array elements along given axis ignoring NaNs.

float64 intermediate and return values are used for integer inputs.

Parameters :

arr : array_like

Array containing numbers whose mean is desired. If arr is not an array, a conversion is attempted.

axis : {int, None}, optional

Axis along which the mean is computed. The default (axis=None) is to compute the mean of the flattened array.

Returns :

y : ndarray

An array with the same shape as arr, with the specified axis removed. If arr is a 0-d array, or if axis is None, a scalar is returned. float64 intermediate and return values are used for integer inputs.

See also

bottleneck.nanmedian
Median along specified axis, ignoring NaNs.

Notes

No error is raised on overflow. (The sum is computed and then the result is divided by the number of non-NaN elements.)

If positive or negative infinity are present the result is positive or negative infinity. But if both positive and negative infinity are present, the result is Not A Number (NaN).

Examples

>>> bn.nanmean(1)
1.0
>>> bn.nanmean([1])
1.0
>>> bn.nanmean([1, np.nan])
1.0
>>> a = np.array([[1, 4], [1, np.nan]])
>>> bn.nanmean(a)
2.0
>>> bn.nanmean(a, axis=0)
array([ 1.,  4.])

When positive infinity and negative infinity are present:

>>> bn.nanmean([1, np.nan, np.inf])
inf
>>> bn.nanmean([1, np.nan, np.NINF])
-inf
>>> bn.nanmean([1, np.nan, np.inf, np.NINF])
nan

bottleneck.nanstd(arr, axis=None, int ddof=0)

Standard deviation along the specified axis, ignoring NaNs.

float64 intermediate and return values are used for integer inputs.

Instead of a faster one-pass algorithm, a more stable two-pass algorithm is used.

An example of a one-pass algorithm:

>>> np.sqrt((arr*arr).mean() - arr.mean()**2)

An example of a two-pass algorithm:

>>> np.sqrt(((arr - arr.mean())**2).mean())

Note in the two-pass algorithm the mean must be found (first pass) before the squared deviation (second pass) can be found.

Parameters :

arr : array_like

Input array. If arr is not an array, a conversion is attempted.

axis : {int, None}, optional

Axis along which the standard deviation is computed. The default (axis=None) is to compute the standard deviation of the flattened array.

ddof : int, optional

Means Delta Degrees of Freedom. The divisor used in calculations is N - ddof, where N represents the number of elements. By default ddof is zero.

Returns :

y : ndarray

An array with the same shape as arr, with the specified axis removed. If arr is a 0-d array, or if axis is None, a scalar is returned. float64 intermediate and return values are used for integer inputs.

See also

bottleneck.nanvar
Variance along specified axis ignoring NaNs

Notes

If positive or negative infinity are present the result is Not A Number (NaN).

Examples

>>> bn.nanstd(1)
0.0
>>> bn.nanstd([1])
0.0
>>> bn.nanstd([1, np.nan])
0.0
>>> a = np.array([[1, 4], [1, np.nan]])
>>> bn.nanstd(a)
1.4142135623730951
>>> bn.nanstd(a, axis=0)
array([ 0.,  0.])

When positive infinity or negative infinity are present NaN is returned:

>>> bn.nanstd([1, np.nan, np.inf])
nan

bottleneck.nanargmin(arr, axis=None)

Indices of the minimum values along an axis, ignoring NaNs.

Parameters :

a : array_like

Input data.

axis : {int, None}, optional

Axis along which to operate. By default (axis=None) flattened input is used.

Returns :

index_array : ndarray

An array of indices or a single index value.

See also

bottleneck.nanargmax
Indices of the maximum values along an axis.
bottleneck.nanmin
Minimum values along specified axis, ignoring NaNs.

Examples

>>> a = np.array([[np.nan, 4], [2, 3]])
>>> bn.nanargmin(a)
2
>>> a.flat[1]
2.0
>>> bn.nanargmax(a, axis=0)
array([1, 1])
>>> bn.nanargmax(a, axis=1)
array([1, 0])

bottleneck.nanargmax(arr, axis=None)

Indices of the maximum values along an axis, ignoring NaNs.

Parameters :

a : array_like

Input data.

axis : {int, None}, optional

Axis along which to operate. By default (axis=None) flattened input is used.

Returns :

index_array : ndarray

An array of indices or a single index value.

See also

bottleneck.nanargmin
Indices of the minimum values along an axis.
bottleneck.nanmax
Maximum values along specified axis, ignoring NaNs.

Examples

>>> a = np.array([[np.nan, 4], [2, 3]])
>>> bn.nanargmax(a)
1
>>> a.flat[1]
4.0
>>> bn.nanargmax(a, axis=0)
array([1, 0])
>>> bn.nanargmax(a, axis=1)
array([1, 1])

Functions

Miscellaneous functions.


bottleneck.nanrankdata(arr, axis=None)

Ranks the data, dealing with ties and NaNs appropriately.

Equal values are assigned a rank that is the average of the ranks that would have been otherwise assigned to all of the values within that set. Ranks begin at 1, not 0.

NaNs in the input array are returned as NaNs.

Parameters :

arr : array_like

Input array. If arr is not an array, a conversion is attempted.

axis : {int, None}, optional

Axis along which the elements of the array are ranked. The default (axis=None) is to rank the elements of the flattened array.

Returns :

y : ndarray

An array with the same shape as arr. The dtype is ‘float64’.

See also

bottleneck.rankdata
Ranks the data, dealing with ties and appropriately.

Examples

>>> bn.nanrankdata([np.nan, 2, 2, 3])
array([ nan,  1.5,  1.5,  3. ])
>>> bn.nanrankdata([[np.nan, 2], [2, 3]])
array([ nan,  1.5,  1.5,  3. ])
>>> bn.nanrankdata([[np.nan, 2], [2, 3]], axis=0)
array([[ nan,   1.],
       [  1.,   2.]])
>>> bn.nanrankdata([[np.nan, 2], [2, 3]], axis=1)
array([[ nan,   1.],
       [  1.,   2.]])

bottleneck.nanvar(arr, axis=None, int ddof=0)

Variance along the specified axis, ignoring NaNs.

float64 intermediate and return values are used for integer inputs.

Instead of a faster one-pass algorithm, a more stable two-pass algorithm is used.

An example of a one-pass algorithm:

>>> np.sqrt((arr*arr).mean() - arr.mean()**2)

An example of a two-pass algorithm:

>>> np.sqrt(((arr - arr.mean())**2).mean())

Note in the two-pass algorithm the mean must be found (first pass) before the squared deviation (second pass) can be found.

Parameters :

arr : array_like

Input array. If arr is not an array, a conversion is attempted.

axis : {int, None}, optional

Axis along which the variance is computed. The default (axis=None)is to compute the variance of the flattened array.

ddof : int, optional

Means Delta Degrees of Freedom. The divisor used in calculations is N - ddof, where N represents the number of elements. By default ddof is zero.

Returns :

y : ndarray

An array with the same shape as arr, with the specified axis removed. If arr is a 0-d array, or if axis is None, a scalar is returned. float64 intermediate and return values are used for integer inputs.

See also

bottleneck.nanstd
Standard deviation along specified axis ignoring NaNs.

Notes

If positive or negative infinity are present the result is Not A Number (NaN).

Examples

>>> bn.nanvar(1)
0.0
>>> bn.nanvar([1])
0.0
>>> bn.nanvar([1, np.nan])
0.0
>>> a = np.array([[1, 4], [1, np.nan]])
>>> bn.nanvar(a)
2.0
>>> bn.nanvar(a, axis=0)
array([ 0.,  0.])

When positive infinity or negative infinity are present NaN is returned:

>>> bn.nanvar([1, np.nan, np.inf])
nan

bottleneck.partsort(arr, n, axis=-1)

Partial sorting of array elements along given axis.

A partially sorted array is one in which the n smallest values appear (in any order) in the first n elements. The remaining largest elements are also unordered. Due to the algorithm used (Wirth’s method), the nth smallest element is in its sorted position (at index n-1).

Shuffling the input array may change the output. The only guarantee is that the first n elements will be the n smallest and the remaining element will appear in the remainder of the output.

This functions is not protected against NaN. Therefore, you may get unexpected results if the input contains NaN.

Parameters :

arr : array_like

Input array. If arr is not an array, a conversion is attempted.

n : int

The n smallest elements will appear (unordered) in the first n elements of the output array.

axis : {int, None}, optional

Axis along which the partial sort is performed. The default (axis=-1) is to sort along the last axis.

Returns :

y : ndarray

A partially sorted copy of the input array where the n smallest elements will appear (unordered) in the first n elements.

See also

bottleneck.argpartsort
Indices that would partially sort an array

Notes

Unexpected results may occur if the input array contains NaN.

Examples

Create a numpy array:

>>> a = np.array([1, 0, 3, 4, 2])

Partially sort array so that the first 3 elements are the smallest 3 elements (note, as in this example, that the smallest 3 elements may not be sorted):

>>> bn.partsort(a, n=3)
array([1, 0, 2, 4, 3])

bottleneck.argpartsort(arr, n, axis=-1)

Return indices that would partially sort an array.

A partially sorted array is one in which the n smallest values appear (in any order) in the first n elements. The remaining largest elements are also unordered. Due to the algorithm used (Wirth’s method), the nth smallest element is in its sorted position (at index n-1).

Shuffling the input array may change the output. The only guarantee is that the first n elements will be the n smallest and the remaining element will appear in the remainder of the output.

This functions is not protected against NaN. Therefore, you may get unexpected results if the input contains NaN.

Parameters :

arr : array_like

Input array. If arr is not an array, a conversion is attempted.

n : int

The indices of the n smallest elements will appear in the first n elements of the output array along the given axis.

axis : {int, None}, optional

Axis along which the partial sort is performed. The default (axis=-1) is to sort along the last axis.

Returns :

y : ndarray

An array the same shape as the input array containing the indices that partially sort arr such that the n smallest elements will appear (unordered) in the first n elements.

See also

bottleneck.partsort
Partial sorting of array elements along given axis.

Notes

Unexpected results may occur if the input array contains NaN.

Examples

Create a numpy array:

>>> a = np.array([1, 0, 3, 4, 2])

Find the indices that partially sort that array so that the first 3 elements are the smallest 3 elements:

>>> index = bn.argpartsort(a, n=3)
>>> index
array([0, 1, 4, 3, 2])

Let’s use the indices to partially sort the array (note, as in this example, that the smallest 3 elements may not be in order):

>>> a[index]
array([1, 0, 2, 4, 3])

Moving window functions

Moving window functions with a 1d window.


bottleneck.move_sum(arr, int window, int axis=-1)

Moving window sum along the specified axis.

Parameters :

arr : ndarray

Input array.

window : int

The number of elements in the moving window.

axis : int, optional

The axis over which to perform the moving sum. By default the moving sum is taken over the last axis (axis=-1). An axis of None is not allowed.

Returns :

y : ndarray

The moving sum of the input array along the specified axis. The output has the same shape as the input.

Examples

>>> arr = np.array([1.0, 2.0, 3.0, 4.0])
>>> bn.move_sum(arr, window=2)
array([ nan,  3.,  5.,  7.])

bottleneck.move_nansum(arr, int window, int axis=-1)

Moving window sum along the specified axis, ignoring NaNs.

Parameters :

arr : ndarray

Input array.

window : int

The number of elements in the moving window.

axis : int, optional

The axis over which to perform the moving sum. By default the moving sum is taken over the last axis (axis=-1). An axis of None is not allowed.

Returns :

y : ndarray

The moving sum of the input array along the specified axis. The output has the same shape as the input.

Examples

>>> arr = np.array([1.0, 2.0, 3.0, 4.0])
>>> bn.move_nansum(arr, window=2)
array([ nan,  3.,  5.,  7.])

bottleneck.move_mean(arr, int window, int axis=-1)

Moving window mean along the specified axis.

Parameters :

arr : ndarray

Input array.

window : int

The number of elements in the moving window.

axis : int, optional

The axis over which to perform the moving mean. By default the moving mean is taken over the last axis (axis=-1). An axis of None is not allowed.

Returns :

y : ndarray

The moving mean of the input array along the specified axis. The output has the same shape as the input.

Examples

>>> arr = np.array([1.0, 2.0, 3.0, 4.0])
>>> bn.move_mean(arr, window=2)
array([ nan,  1.5,  2.5,  3.5])

bottleneck.move_nanmean(arr, int window, int axis=-1)

Moving window mean along the specified axis, ignoring NaNs.

Parameters :

arr : ndarray

Input array.

window : int

The number of elements in the moving window.

axis : int, optional

The axis over which to perform the moving mean. By default the moving mean is taken over the last axis (axis=-1). An axis of None is not allowed.

Returns :

y : ndarray

The moving mean of the input array along the specified axis. The output has the same shape as the input.

Examples

>>> arr = np.array([1.0, 2.0, 3.0, 4.0])
>>> bn.move_nanmean(arr, window=2)
array([ nan,  1.5,  2.5,  3.5])

bottleneck.move_median(arr, int window, int axis=-1)

Moving window median along the specified axis.

This functions is not protected against NaN. Therefore, you may get unexpected results if the input contains NaN.

Parameters :

arr : ndarray

Input array.

window : int

The number of elements in the moving window.

axis : int, optional

The axis over which to perform the moving median. By default the moving median is taken over the last axis (axis=-1). An axis of None is not allowed.

Returns :

y : ndarray

The moving median of the input array along the specified axis. The output has the same shape as the input.

Notes

Unexpected results may occur if the input array contains NaN.

Examples

>>> arr = np.array([1.0, 2.0, 3.0, 4.0])
>>> bn.move_median(arr, window=2)
array([ nan,  1.5,  2.5,  3.5])

bottleneck.move_std(arr, int window, int axis=-1, int ddof=0)

Moving window standard deviation along the specified axis.

Unlike bn.nanstd, which uses a more rubust two-pass algorithm, move_std uses a faster one-pass algorithm.

An example of a one-pass algorithm:

>>> np.sqrt((arr*arr).mean() - arr.mean()**2)

An example of a two-pass algorithm:

>>> np.sqrt(((arr - arr.mean())**2).mean())

Note in the two-pass algorithm the mean must be found (first pass) before the squared deviation (second pass) can be found.

Parameters :

arr : ndarray

Input array.

window : int

The number of elements in the moving window.

axis : int, optional

The axis over which to perform the moving standard deviation. By default the moving standard deviation is taken over the last axis (axis=-1). An axis of None is not allowed.

Returns :

y : ndarray

The moving standard deviation of the input array along the specified axis. The output has the same shape as the input.

Examples

>>> arr = np.array([1.0, 2.0, 3.0, 4.0])
>>> bn.move_std(arr, window=2)
array([ nan,  1.5,  2.5,  3.5])

bottleneck.move_nanstd(arr, int window, int axis=-1, int ddof=0)

Moving window standard deviation along the specified axis, ignoring NaNs.

Unlike bn.nanstd, which uses a more rubust two-pass algorithm, move_nanstd uses a faster one-pass algorithm.

An example of a one-pass algorithm:

>>> np.sqrt((arr*arr).mean() - arr.mean()**2)

An example of a two-pass algorithm:

>>> np.sqrt(((arr - arr.mean())**2).mean())

Note in the two-pass algorithm the mean must be found (first pass) before the squared deviation (second pass) can be found.

Parameters :

arr : ndarray

Input array.

window : int

The number of elements in the moving window.

axis : int, optional

The axis over which to perform the moving standard deviation. By default the moving standard deviation is taken over the last axis (axis=-1). An axis of None is not allowed.

Returns :

y : ndarray

The moving standard deviation of the input array along the specified axis. The output has the same shape as the input.

Examples

>>> arr = np.array([1.0, 2.0, 3.0, 4.0])
>>> bn.move_nanstd(arr, window=2)
array([ nan,  1.5,  2.5,  3.5])

bottleneck.move_min(arr, int window, int axis=-1)

Moving window minimum along the specified axis.

float64 output is returned for all input data types.

Parameters :

arr : ndarray

Input array.

window : int

The number of elements in the moving window.

axis : int, optional

The axis over which to find the moving minimum. By default the moving minimum is taken over the last axis (axis=-1). An axis of None is not allowed.

Returns :

y : ndarray

The moving minimum of the input array along the specified axis. The output has the same shape as the input.

Examples

>>> arr = np.array([1.0, 2.0, 4.0, 3.0])
>>> bn.move_min(arr, window=2)
array([ nan,  1.,  2.,  3.])

bottleneck.move_nanmin(arr, int window, int axis=-1)

Moving window minimum along the specified axis, ignoring NaNs.

float64 output is returned for all input data types.

Parameters :

arr : ndarray

Input array.

window : int

The number of elements in the moving window.

axis : int, optional

The axis over which to find the moving minimum. By default the moving minimum is taken over the last axis (axis=-1). An axis of None is not allowed.

Returns :

y : ndarray

The moving minimum of the input array along the specified axis. The output has the same shape as the input.

Examples

>>> arr = np.array([1.0, 2.0, 4.0, 3.0])
>>> bn.move_nanmin(arr, window=2)
array([ nan,  2.,  4.,  4.])

bottleneck.move_max(arr, int window, int axis=-1)

Moving window maximum along the specified axis.

float64 output is returned for all input data types.

Parameters :

arr : ndarray

Input array.

window : int

The number of elements in the moving window.

axis : int, optional

The axis over which to find the moving maximum. By default the moving maximum is taken over the last axis (axis=-1). An axis of None is not allowed.

Returns :

y : ndarray

The moving maximum of the input array along the specified axis. The output has the same shape as the input.

Examples

>>> arr = np.array([1.0, 2.0, 4.0, 3.0])
>>> bn.move_max(arr, window=2)
array([ nan,  2.,  4.,  4.])

bottleneck.move_nanmax(arr, int window, int axis=-1)

Moving window maximum along the specified axis, ignoring NaNs.

float64 output is returned for all input data types.

Parameters :

arr : ndarray

Input array.

window : int

The number of elements in the moving window.

axis : int, optional

The axis over which to find the moving maximum. By default the moving maximum is taken over the last axis (axis=-1). An axis of None is not allowed.

Returns :

y : ndarray

The moving maximum of the input array along the specified axis. The output has the same shape as the input.

Examples

>>> arr = np.array([1.0, 2.0, 4.0, 3.0])
>>> bn.move_nanmax(arr, window=2)
array([ nan,  2.,  4.,  4.])

Table Of Contents

Previous topic

Bottleneck

Next topic

Release Notes

This Page