python Numpy transpose and calculate
<p>I am relatively new to python and numpy. I am currently trying to replicate the following table as shown in the image in python using numpy.</p>

<p><a href="http://i.stack.imgur.com/nVKbb.png" rel="nofollow"><img src="http://i.stack.imgur.com/nVKbb.png" alt="enter image description here"></a>
As in the figure, I have got the columns "group, sub_group,value" that are populated. I want to transpose column "sub_group" and do a simple calculation i.e. value minus shift(value) and display the figure in the lower diagonal of the matrix for each group. If sub_group is "0", then assign the whole column as 0. The <strong>transposed sub_group</strong> can be named anything (preferably index numbers) if it makes it easier. I am ok with a pandas solution as well. I just think pandas may be slow?</p>

<p>Below is code in array form:</p>

<pre><code>import numpy as np
a=np.array([(1,-1,10),(1,0,10),(1,-2,15),(1,-3,1),(1,-4,1),(1,0,12),(1,-5,16)], dtype=[('group',float),('sub_group',float),('value',float)])
</code></pre>

<p>Any help would be appreciated.
Regards,
S</p>

<p>This piece of code does the calculation for the example of the subgroup, I am not  sure if this is what you actually want, in that case post a comment here and I will edit</p>

<pre><code>import numpy as np
array_1=np.array([(1,-1,10),(1,0,10),(1,-2,15),(1,-3,1),(1,-4,1);(1,0,12),(1,-5,16)])
#transpose the matrix
transposed_group = array_1.transpose()
#loop over the first row
for i in range(0,len(transposed_group[1,:])):
#value[i] - first value of the row
    transposed_group[0,i] = transposed_group[0,i] - transposed_group[0,0]
print  transposed_group
</code></pre>

<p>In case you want to display that in the diagonal of the matrix, you can loop through the rows and columns, as for example: </p>

<pre><code>import numpy as np
#create an array of 0
array = np.zeros(shape=(3,3))
#fill the array with 1 in the diagonals
print array
#loop over rows
for i in range(0,len(array[:,1])):
    #loop over columns
    for j in range(0,len(array[1,:])):
        array[i,j] = 1

print array
</code></pre>

python arrays pandas numpy