I have numpy matrices collected in the list. I need to built an array which contains particular entry from each matrix, for example second entry from each matrix. I would like to avoid loop.
The data is already in this shape, I don't want to change the structure or change matrices into something else.
Example code - data structure:
L = []
m1 = np.mat([ 1, 2, 3]).T
m2 = np.mat([ 4, 5, 6]).T
m3 = np.mat([ 7, 8, 9]).T
m4 = np.mat([10,11,12]).T
m5 = np.mat([13,14,15]).T
L.append(m1)
L.append(m2)
L.append(m3)
L.append(m4)
L.append(m5)
The only way I managed to do it is through the loop:
S = []
for k in range(len(L)):
S.append(L[k][1,0])
print 'S = %s' % S
the output I need: S = [2, 5, 8, 11, 14]
I thought something like: S1 = np.array(L[:][1,0])
should work but whatever I try I have the error like: TypeError: list indices must be integers, not tuple
. What is the efficient way (numpy style) of accessing it?