Skip to content


Subversion checkout URL

You can clone with
Download ZIP


argrelextrema returns tuple of 2 empty arrays when no peaks found in 1D vector #2832

dmcminniwc opened this Issue · 3 comments

3 participants


When using the scipy.signal.argrelextrema function to find the peaks in a 1D numpy vector and no peaks are found the return value is a tuple with two empty arrays.

The docs say it returns "Indices of the maxima, as an array of integers". I would expect with no peaks it would be a tuple with one empty array for each dimension of the input vector.

For example:

import numpy as np
import scipy.signal as sig
y = np.concatenate([np.arange(1, 0, -0.01), np.arange(0, 1, 0.01)]) 
peaks = sig.argrelextrema(0.5-np.abs(y - 0.5), np.greater)
print peaks # Prints '(array([ 50, 150]),)'
peaks = sig.argrelextrema(y, np.greater) # No peaks
print peaks # Prints '((array([]), dtype=float64),(array([]), dtype=float64),)'

I would have expected '((array([]), dtype=float64),)' for the second print statement.

In the source for scipy it returns "(np.array([]),) * 2" when no peaks are found but it should probably be "(np.array([]),) * data.ndim".


I forgot to add that this was using scipy v 0.12.0 on Windows 7 x64 Professional, running on python 2.7.5.


This issue has been discussed on the Scipy-User Mailinglist:


This is fixed by #2836

@WarrenWeckesser WarrenWeckesser closed this issue from a commit
@WarrenWeckesser WarrenWeckesser MAINT: signal: Some clean up in
* Fixed the description of the return value of argrelmin, argrelmax,
  argrelextrema and _boolrelextream.
* Fixed the example in the docstring of _boolrelextream.
* Added examples to the docstrings of argrelmin, argrelmax and
* Added more tests for argrelmin and argrelmax.
* Removed some commented-out code and unused imports from
  along with an unused variable (num_peaks) in _gen_gaussians().
* Removed an argument ('order=2') from the signature of
  TestArgrel.test_higher_order() in
* Removed unnecessary special check in argrelextrema that incorrectly
  returned a length 2 tuple when there were no relative extrema,
  regardless of the dimension of the input.  Fixes gh-2832.
* Several more minor tweaks.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.