# Can get\_peak function specify the maximum or minimum value?

**URL:** <https://mne.discourse.group/t/can-get-peak-function-specify-the-maximum-or-minimum-value/2673>\
**Category:** Support & Discussions\
**Tags:** eeg\
**Created:** [February 6, 2021, 11:49am UTC](https://mne.discourse.group/t/can-get-peak-function-specify-the-maximum-or-minimum-value/2673 "2021-02-06T11:49:55Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![elvisjade](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/elvisjade/32/122_2.png) [@elvisjade](https://mne.discourse.group/u/elvisjade)\
**Post date:** [February 6, 2021, 11:49am UTC](https://mne.discourse.group/t/can-get-peak-function-specify-the-maximum-or-minimum-value/2673/1 "2021-02-06T11:49:55Z")

</div>

I would like to ask whether the get\_peak function can specify the maximum or minimum value?

I want to request the peak value in the erp data, but there are some I want to find the maximum value, and some want to find the minimum value. I want to ask whether the get\_peak function can specify the maximum or minimum value.

I don’t understand what this means in the tutorial.This means that if I choose pos or neg, it means that only data with positive or negative values ​​is considered?  
mode: {‘pos’,‘neg’,‘abs’}  
How to deal with the sign of the data. If ‘pos’ only positive values ​​will be considered. If ‘neg’ only negative values ​​will be considered. If ‘abs’ absolute values ​​will be considered. Defaults to ‘abs’.

And it seems to say The amplitude of the maximum response.

Does this mean that I can only find the peak of the maximum? Can’t find the peak of the minimum?  
[https://mne.tools/stable/generated/mne.EvokedArray.html?highlight=get\_peak#mne.EvokedArray.get\_peak](https://mne.tools/stable/generated/mne.EvokedArray.html?highlight=get_peak#mne.EvokedArray.get_peak)

I also tried the mne.preprocessing.peak\_finder function, but this function does not support evoke data and I need to convert it to a 1d array. It will return multiple peaks, and it seems that it will not return the latency directly, but will return the index I need to convert it to the latency by myself.

I want to ask if there is a good way to specify the maximum peak or minimum peak?  
[https://mne.tools/stable/generated/mne.preprocessing.peak\_finder.html?highlight=peak%20finder#mne.preprocessing.peak\_finder](https://mne.tools/stable/generated/mne.preprocessing.peak_finder.html?highlight=peak%20finder#mne.preprocessing.peak_finder)

Very grateful for your help!  
Looking forward to your reply!

---

<div class="post-metadata">

**Author:** ![richard](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/richard/32/15_2.png) [@richard](https://mne.discourse.group/u/richard)\
**Post date:** [February 6, 2021, 4:25pm UTC](https://mne.discourse.group/t/can-get-peak-function-specify-the-maximum-or-minimum-value/2673/2 "2021-02-06T16:25:00Z")

</div>

[`Evoked.get_peak()`](https://mne.tools/stable/generated/mne.Evoked.html#mne.Evoked.get_peak) can search for peaks in the following ways:

1. take the absolute value of the data (i.e., turn everything into non-negative values), and find the largest value of that (that’s the default, `mode='abs'`)

2. only consider positive values (i.e., `>0`), and find the highest value (`mode='pos'`)

3. only consider negative values (i.e., `<0`), and find the smallest value (`mode='neg'`)

There is currently no way to use `get_peak()` to find the smallest value of a signal that’s always positive; or the largest value of a signal that’s exclusively negative.

---

<div class="post-metadata">

**Author:** ![elvisjade](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/elvisjade/32/122_2.png) [@elvisjade](https://mne.discourse.group/u/elvisjade)\
**Post date:** [February 7, 2021, 1:14am UTC](https://mne.discourse.group/t/can-get-peak-function-specify-the-maximum-or-minimum-value/2673/3 "2021-02-07T01:14:42Z")

</div>

I would like to ask what is the better way to find the smallest value of a signal that’s always positive; or the largest value of a signal that’s exclusively negative?

---

<div class="post-metadata">

**Author:** ![richard](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/richard/32/15_2.png) [@richard](https://mne.discourse.group/u/richard)\
**Post date:** [February 7, 2021, 9:05am UTC](https://mne.discourse.group/t/can-get-peak-function-specify-the-maximum-or-minimum-value/2673/4 "2021-02-07T09:05:11Z")

</div>

You can use `np.argmin(evoked.data, axis=1)` and `np.argmax(evoked.data, axis=1)` to get the indices of the minimum and maximum values, respectively, and use the result to retrieve the respective time points:

```python
idx_min = np.argmin(evoked.data, axis=1) # min for each channel
idx_max = np.argmax(evoked.data, axis=1) # max for each channel

t_signal_min = evoked.times[idx_min]
t_signal_max = evoked.times[idx_max]

```

---

<div class="post-metadata">

**Author:** ![elvisjade](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/elvisjade/32/122_2.png) [@elvisjade](https://mne.discourse.group/u/elvisjade)\
**Post date:** [February 11, 2021, 10:10am UTC](https://mne.discourse.group/t/can-get-peak-function-specify-the-maximum-or-minimum-value/2673/5 "2021-02-11T10:10:47Z")

</div>

Thank you very much for your help and your reply.  
I understand how to do it.  
Thank you very much!
