November 22nd, 2012, 11:41 AM

Something about matrices
Hi, i read a lot about slicing, indexing and arrays, but nothing seems to work in this simple case, that with matlab i resolve rapidly.
I have n matrices, of the same dimension [h : m].
I want to make a cicle from i=0 to n, so that i can take one matrix, extract its first column and put this one in another matrix that i call X, that now is still empty.
So, in the first iteration I take the first column of the first matrix and put it in the first column of Xmatrix, the second iteration takes the first column of second matrix and puts it in the second column of Xmatrix, and so on.
It seems not so difficult, but i tried different ways, but or it doesn't recognize iterative index i as appropriate, or it creates only a row from my columns, or the empty matrix X is bad declared... each time a different way and each time a different problem
so, how can i do?
thanks again
November 23rd, 2012, 10:51 AM

Code:
import scipy
a=[[0,1],[2,3]] # rows are 0 1 and 2 3
b=[[4,5],[6,7]]
def transpose(A):
return list(zip(*A))
input_list = [transpose(A) for A in [a,b]]
cT = [A[i] for (i,A) in enumerate(input_list)]
c = transpose(cT)
print(c)
Consider instead installing scipy or numpy from the enthought python distribution.
Code:
>>> a = scipy.arange(4).reshape((2,2))
>>> b = a+4 # array operations similar to matlab
array([[0, 1],
[2, 3]])
>>> b
array([[4, 5],
[6, 7]])
>>> a[:,0:1] # index a column vector similar to matlab
array([[0],
[2]])
>>> scipy.concatenate
<builtin function concatenate>
>>> a.transpose()
array([[0, 2],
[1, 3]])
>>> # I don't recall how to stitch columns with scipy.
>>>
[code]
Code tags[/code] are essential for python code and Makefiles!
November 28th, 2012, 09:59 AM

well, it seems to be really difficult compared to matlab...
anyway, I studied better tutorials of numpy about arrays, and with your help I made up many interesting things. not bad... thanks again... I'll be back soon to disturb with topics about plotting
November 28th, 2012, 10:17 AM

For what it's worth, I reviewed (link) a book on numpy.
I program in j. www.jsoftware.com
Arbitrary rank arrays are the only data structure.
[code]
Code tags[/code] are essential for python code and Makefiles!