Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #46587 > unrolled thread

Finding Relative Maxima in Python3

Started byLourens-Jan Ugen <lourensjan.ugen@gmail.com>
First post2013-05-31 02:41 -0700
Last post2013-05-31 02:54 -0700
Articles 2 — 2 participants

Back to article view | Back to comp.lang.python


Contents

  Finding Relative Maxima in Python3 Lourens-Jan Ugen <lourensjan.ugen@gmail.com> - 2013-05-31 02:41 -0700
    Re: Finding Relative Maxima in Python3 Chris Rebert <clp2@rebertia.com> - 2013-05-31 02:54 -0700

#46587 — Finding Relative Maxima in Python3

FromLourens-Jan Ugen <lourensjan.ugen@gmail.com>
Date2013-05-31 02:41 -0700
SubjectFinding Relative Maxima in Python3
Message-ID<6acf9ce5-eed1-4115-aa93-71d2e182db79@googlegroups.com>
Hi all,

The last few days I've been working on a script to manipulate some scientific data. One thing I would like to be able to do is find relative maxima in a data set. 
I'm using numpy in python3 (which I think I can't do without because of utf16 encoding of my data source) and a series of np.arrays. When looking around the web and some forums I came across the scipy function argrelextrema, which seemed to do just what I wanted. The problem is that I can't get the function to work, probably because scipy in python3 does not yet support the argrelextrema function. I can however, not find a reference to this really being the problem, and was wondering if someone here could maybe help me out.
The code I used is shown below. The function to return the maximum values is called by a different script. Then, when running, it returns an error like the one below the code. 

Script:
import numpy as np
import scipy as sp

def max_in_array_range(MaxArray, Column, LowBound):
	'''
	Finding the max value an array with a predefined in a certain column and from a threshold index.
	The complete array is loaded through Max Array. The column is first selected. 
	The, the LowBound is called (the data is only interesting from a certain point onward.
	'''
	TempArray = MaxArray[:, Column]	# Creation of Temporary Array to ensure 1D Array and specification of the LowBound in the next line.
	return sp.argrelextrema(TempArray[LowBound:], np.greater)


Error message:
Traceback (most recent call last):
  File "MyScript.py", line 15, in <module>
    Varrr = FD.max_in_array_range(CalcAndDiffArray, 5 ,MyBound)
  File "/MyPath/Script.py", line 82, in max_in_array_range
    return sp.argrelmax(TempArray[LowBound:], np.greater)
AttributeError: 'module' object has no attribute 'argrelmax'

[toc] | [next] | [standalone]


#46589

FromChris Rebert <clp2@rebertia.com>
Date2013-05-31 02:54 -0700
Message-ID<mailman.2481.1369994087.3114.python-list@python.org>
In reply to#46587

[Multipart message — attachments visible in raw view] — view raw

On May 31, 2013 2:46 AM, "Lourens-Jan Ugen" <lourensjan.ugen@gmail.com>
wrote:
>
> Hi all,
>
> The last few days I've been working on a script to manipulate some
scientific data. One thing I would like to be able to do is find relative
maxima in a data set.
> I'm using numpy in python3 (which I think I can't do without because of
utf16 encoding of my data source) and a series of np.arrays. When looking
around the web and some forums I came across the scipy function
argrelextrema, which seemed to do just what I wanted. The problem is that I
can't get the function to work, probably because scipy in python3 does not
yet support the argrelextrema function. I can however, not find a reference
to this really being the problem, and was wondering if someone here could
maybe help me out.
> The code I used is shown below. The function to return the maximum values
is called by a different script. Then, when running, it returns an error
like the one below the code.
>
> Script:
> import numpy as np
> import scipy as sp
<snip>
> Error message:
> Traceback (most recent call last):
>   File "MyScript.py", line 15, in <module>
>     Varrr = FD.max_in_array_range(CalcAndDiffArray, 5 ,MyBound)
>   File "/MyPath/Script.py", line 82, in max_in_array_range
>     return sp.argrelmax(TempArray[LowBound:], np.greater)
> AttributeError: 'module' object has no attribute 'argrelmax'

The docs would seem to indicate that that function resides in the "signal"
submodule of scipy:
http://docs.scipy.org/doc/scipy-dev/reference/generated/scipy.signal.argrelmax.html#scipy.signal.argrelmax

Hence, it would be sp.signal.argrelmax() as opposed to just sp.argrelmax()

Cheers,
Chris

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web