why use transpose than directly set array?
<p>In a python code I see two lines below (initially, labels was of type (15093, that is, 1-d array)(from py-faster-rcnn)</p>

<pre><code>labels = labels.reshape((1, height, width, A)).transpose(0, 3, 1, 2)
labels = labels.reshape((1, 1, A * height, width))
</code></pre>

<p>Is there any reason the author use transpose than directly set</p>

<pre><code>labels = labels.reshape((1, A, height, width))
labels = labels.reshape((1, 1, A * height, width))
</code></pre>

<p>Or even,</p>

<pre><code>labels = labels.reshape((1, 1, A * height, width))
</code></pre>

<p>?  (I guess it's related to the data order in the initial labels array)</p>

<p>The answer is quite easy : yes there is a reason, given the same <code>labels</code> array, the results of your 3 methods simply aren't the same. </p>

<p>Lets check that with an example:</p>

<pre><code>import numpy as np
height, width, A = [2,3,4]
arr=np.random.rand(1*height*width*A)

print("Method 1")
labels1=np.copy(arr)
labels1 = labels1.reshape((1, height, width, A)).transpose(0, 3, 1, 2)
labels1 = labels1.reshape((1, 1, A * height, width))
print(labels1)

print("Method 2")
labels2=np.copy(arr)
labels2 = labels2.reshape((1, A, height, width))
labels2 = labels2.reshape((1, 1, A * height, width))
print(labels2)

print("Method 3")
labels3=np.copy(arr)
labels3 = labels3.reshape((1, 1, A * height, width))
print(labels3)
</code></pre>

<p>Which gives:</p>

<pre><code>&gt;&gt;&gt; Method 1
&gt;&gt;&gt; [[[[ 0.97360395  0.40639034  0.92936386]
&gt;&gt;&gt;    [ 0.01687321  0.94744919  0.39188023]
&gt;&gt;&gt;    [ 0.34210967  0.36342341  0.6938464 ]
&gt;&gt;&gt;    [ 0.60065943  0.00356836  0.91785409]
&gt;&gt;&gt;    [ 0.57095964  0.61036102  0.17318427]
&gt;&gt;&gt;    [ 0.38002045  0.08596757  0.29407445]
&gt;&gt;&gt;    [ 0.95899964  0.13046103  0.36286533]
&gt;&gt;&gt;    [ 0.86970793  0.11659624  0.82073826]]]]
&gt;&gt;&gt; Method 2
&gt;&gt;&gt; [[[[ 0.97360395  0.34210967  0.57095964]
&gt;&gt;&gt;    [ 0.95899964  0.40639034  0.36342341]
&gt;&gt;&gt;    [ 0.61036102  0.13046103  0.92936386]
&gt;&gt;&gt;    [ 0.6938464   0.17318427  0.36286533]
&gt;&gt;&gt;    [ 0.01687321  0.60065943  0.38002045]
&gt;&gt;&gt;    [ 0.86970793  0.94744919  0.00356836]
&gt;&gt;&gt;    [ 0.08596757  0.11659624  0.39188023]
&gt;&gt;&gt;    [ 0.91785409  0.29407445  0.82073826]]]]
&gt;&gt;&gt; Method 3
&gt;&gt;&gt; [[[[ 0.97360395  0.34210967  0.57095964]
&gt;&gt;&gt;    [ 0.95899964  0.40639034  0.36342341]
&gt;&gt;&gt;    [ 0.61036102  0.13046103  0.92936386]
&gt;&gt;&gt;    [ 0.6938464   0.17318427  0.36286533]
&gt;&gt;&gt;    [ 0.01687321  0.60065943  0.38002045]
&gt;&gt;&gt;    [ 0.86970793  0.94744919  0.00356836]
&gt;&gt;&gt;    [ 0.08596757  0.11659624  0.39188023]
&gt;&gt;&gt;    [ 0.91785409  0.29407445  0.82073826]]]]
</code></pre>

<p>So method 1 is different from 2 and 3, while 2 and 3 are the same.</p>

python numpy