<p dir="auto">It is similar to issue <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="385718821" data-permission-text="Title is private" data-url="https://github.com/scipy/scipy/issues/9553" data-hovercard-type="issue" data-hovercard-url="/scipy/scipy/issues/9553/hovercard" href="https://github.com/scipy/scipy/issues/9553">#9553</a>. rank_filter function gives wrong result if input and output parameters are the same.</p>
<h3 dir="auto">Reproducing code example:</h3>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="import numpy as np
import scipy.ndimage as ndi

a = np.zeros((3,3))
a[:,0] = 1
print(ndi.rank_filter(a, rank=6, size=3, mode='constant'))
print(ndi.rank_filter(a, rank=6, size=3, mode='constant', output=a))

[[0. 0. 0.]
 [1. 1. 0.]
 [0. 0. 0.]]
[[0. 0. 0.]
 [0. 0. 0.]
 [0. 0. 0.]]"><pre class="notranslate"><code class="notranslate">import numpy as np
import scipy.ndimage as ndi

a = np.zeros((3,3))
a[:,0] = 1
print(ndi.rank_filter(a, rank=6, size=3, mode='constant'))
print(ndi.rank_filter(a, rank=6, size=3, mode='constant', output=a))

[[0. 0. 0.]
 [1. 1. 0.]
 [0. 0. 0.]]
[[0. 0. 0.]
 [0. 0. 0.]
 [0. 0. 0.]]
</code></pre></div>
<h3 dir="auto">Scipy/Numpy/Python version information:</h3>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="import sys, scipy, numpy; print(scipy.__version__, numpy.__version__, sys.version_info)
1.1.0 1.15.4 sys.version_info(major=3, minor=7, micro=1, releaselevel='final', serial=0)"><pre class="notranslate"><code class="notranslate">import sys, scipy, numpy; print(scipy.__version__, numpy.__version__, sys.version_info)
1.1.0 1.15.4 sys.version_info(major=3, minor=7, micro=1, releaselevel='final', serial=0)
</code></pre></div>
<p dir="auto">Maybe the problem is following<br>
...<br>
<em>tmp = grey_erosion(tmp, size, footprint, structure, output, mode, cval, origin)</em><br>
tmp and input is the same now<br>
so<br>
<em>numpy.subtract(tmp, input, out=tmp)</em><br>
gives zero</p>
<p dir="auto">Thank you</p>