Scipy maximum filter for all equal values
<p>I want to use scipy's maximum_filter to detect local maximas, but there is one issue. If the filter applies the function on values that are all equal, it returns all of them as local maximas, but I need to have them the opposite way.</p>

<p>An example script:</p>

<pre><code>import numpy as np
import scipy.ndimage as sc

ones_matrix = np.ones((6,6))

max_arr = (ones_matrix == sc.maximum_filter(ones_matrix, 3, mode = 'constant'))
print max_arr
</code></pre>

<p>This returns all True, but I need them as false. How can I do that? Thanks in advance!</p>

<pre><code>[[ True  True  True  True  True  True]
 [ True  True  True  True  True  True]
 [ True  True  True  True  True  True]
 [ True  True  True  True  True  True]
 [ True  True  True  True  True  True]
 [ True  True  True  True  True  True]]
</code></pre>

<p>You could change your sentence:</p>

<pre><code>max_arr = (ones_matrix == sc.maximum_filter(ones_matrix, 3, mode = 'constant'))
</code></pre>

<p>for this one:</p>

<pre><code>max_arr = (ones_matrix != sc.maximum_filter(ones_matrix, 3, mode = 'constant'))
</code></pre>

python scipy filtering