<p dir="auto">The output of <code class="notranslate">scipy.ndimage.rotate()</code> for a single 180 degree rotation is inconsistent with the result of two consecutive 90 degree rotations. I had expected these should be equivalent. Is this expected behaviour?</p>
<h4 dir="auto">Reproducing code example:</h4>

<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="# Sample code to reproduce the problem
import numpy as np
import scipy.ndimage

arr = np.array([[1, 2], [3, 4]])

scipy.ndimage.rotate(arr, 180)
# produces this unexpected result
# array([[4, 0],
#        [2, 0]])

scipy.ndimage.rotate(scipy.ndimage.rotate(arr, 90), 90)
# whereas two consecutive 90 degree rotations produce a result more like I'd expect
# array([[4, 3],
#        [2, 1]])

np.flip(arr, axis=(0,1))
# I also expect the rotations above should be equal to np.flip(arr, axis=(0, 1))
# array([[4, 3],
#        [2, 1]])
"><pre class="notranslate"><span class="pl-c"># Sample code to reproduce the problem</span>
<span class="pl-k">import</span> <span class="pl-s1">numpy</span> <span class="pl-k">as</span> <span class="pl-s1">np</span>
<span class="pl-k">import</span> <span class="pl-s1">scipy</span>.<span class="pl-s1">ndimage</span>

<span class="pl-s1">arr</span> <span class="pl-c1">=</span> <span class="pl-s1">np</span>.<span class="pl-en">array</span>([[<span class="pl-c1">1</span>, <span class="pl-c1">2</span>], [<span class="pl-c1">3</span>, <span class="pl-c1">4</span>]])

<span class="pl-s1">scipy</span>.<span class="pl-s1">ndimage</span>.<span class="pl-en">rotate</span>(<span class="pl-s1">arr</span>, <span class="pl-c1">180</span>)
<span class="pl-c"># produces this unexpected result</span>
<span class="pl-c"># array([[4, 0],</span>
<span class="pl-c">#        [2, 0]])</span>

<span class="pl-s1">scipy</span>.<span class="pl-s1">ndimage</span>.<span class="pl-en">rotate</span>(<span class="pl-s1">scipy</span>.<span class="pl-s1">ndimage</span>.<span class="pl-en">rotate</span>(<span class="pl-s1">arr</span>, <span class="pl-c1">90</span>), <span class="pl-c1">90</span>)
<span class="pl-c"># whereas two consecutive 90 degree rotations produce a result more like I'd expect</span>
<span class="pl-c"># array([[4, 3],</span>
<span class="pl-c">#        [2, 1]])</span>

<span class="pl-s1">np</span>.<span class="pl-en">flip</span>(<span class="pl-s1">arr</span>, <span class="pl-s1">axis</span><span class="pl-c1">=</span>(<span class="pl-c1">0</span>,<span class="pl-c1">1</span>))
<span class="pl-c"># I also expect the rotations above should be equal to np.flip(arr, axis=(0, 1))</span>
<span class="pl-c"># array([[4, 3],</span>
<span class="pl-c">#        [2, 1]])</span></pre></div>
<h4 dir="auto">Error message:</h4>
<p dir="auto">No error message is produced.</p>
<h4 dir="auto">Scipy/Numpy/Python version information:</h4>

<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="1.3.1 1.17.2 sys.version_info(major=3, minor=7, micro=4, releaselevel='final', serial=0)"><pre class="notranslate"><code class="notranslate">1.3.1 1.17.2 sys.version_info(major=3, minor=7, micro=4, releaselevel='final', serial=0)
</code></pre></div>
<p dir="auto"><em>Original ticket <a href="http://projects.scipy.org/scipy/ticket/1378" rel="nofollow">http://projects.scipy.org/scipy/ticket/1378</a> on 2011-01-29 by trac user tmcookies, assigned to unknown.</em></p>
<p dir="auto">When rotating 3d-structure elements, some values get lost. I have two cases that i can show:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="import numpy as np
from scipy.ndimage import rotate

cTA = np.array([
      [[-1, -1, -1],
       [-1, -1, -1],
       [-1, -1, -1]],
      [[ 0,  0,  0],
       [ 0,  1,  0],
       [ 0,  0,  0]],
      [[ 0,  0,  0],
       [ 0,  1,  0],
       [ 0,  0,  0]]
       ])

cTA1  = rotate(cTA, 90,(0,1))
cTA6  = rotate(cTA,180,(0,1))
cTA6_ = rotate(cTA1,90,(0,1))

print cTA6
print cTA6_"><pre class="notranslate"><code class="notranslate">import numpy as np
from scipy.ndimage import rotate

cTA = np.array([
      [[-1, -1, -1],
       [-1, -1, -1],
       [-1, -1, -1]],
      [[ 0,  0,  0],
       [ 0,  1,  0],
       [ 0,  0,  0]],
      [[ 0,  0,  0],
       [ 0,  1,  0],
       [ 0,  0,  0]]
       ])

cTA1  = rotate(cTA, 90,(0,1))
cTA6  = rotate(cTA,180,(0,1))
cTA6_ = rotate(cTA1,90,(0,1))

print cTA6
print cTA6_
</code></pre></div>
<p dir="auto">The result of cTA6 and cTA6_ should be the same (rotating 180 or two times 90 should be the same), but the 180-rotation loses three values at the bottom array.</p>
<p dir="auto">The result i get is the following:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="[[[ 0  0  0]
  [ 0  1  0]
  [ 0  0  0]]

 [[ 0  0  0]
  [ 0  1  0]
  [ 0  0  0]]

 [[-1 -1 -1]
  [-1 -1 -1]
  [ 0  0  0]]]   __here are the missing '-1' __

[[[ 0  0  0]
  [ 0  1  0]
  [ 0  0  0]]

 [[ 0  0  0]
  [ 0  1  0]
  [ 0  0  0]]

 [[-1 -1 -1]
  [-1 -1 -1]
  [-1 -1 -1]]]"><pre class="notranslate"><code class="notranslate">[[[ 0  0  0]
  [ 0  1  0]
  [ 0  0  0]]

 [[ 0  0  0]
  [ 0  1  0]
  [ 0  0  0]]

 [[-1 -1 -1]
  [-1 -1 -1]
  [ 0  0  0]]]   __here are the missing '-1' __

[[[ 0  0  0]
  [ 0  1  0]
  [ 0  0  0]]

 [[ 0  0  0]
  [ 0  1  0]
  [ 0  0  0]]

 [[-1 -1 -1]
  [-1 -1 -1]
  [-1 -1 -1]]]
</code></pre></div>
<p dir="auto">By the way: i'm running Ubuntu 10.10 32bit (yeah, they still didn't switch to 0.8)</p>