Forums: » Register « |  Free Tools |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |

New Free Tools on Dev Shed!

#1
November 22nd, 2012, 11:41 AM
 giacomo84
Registered User

Join Date: Nov 2012
Posts: 13
Time spent in forums: 3 h 21 m 37 sec
Reputation Power: 0

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 X-matrix, the second iteration takes the first column of second matrix and puts it in the second column of X-matrix, 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

#2
November 23rd, 2012, 10:51 AM
 b49P23TIvg
Contributing User

Join Date: Aug 2011
Posts: 4,214
Time spent in forums: 1 Month 3 Weeks 2 Days 18 h 7 m 36 sec
Reputation Power: 455
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
<built-in 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!

#3
November 28th, 2012, 09:59 AM
 giacomo84
Registered User

Join Date: Nov 2012
Posts: 13
Time spent in forums: 3 h 21 m 37 sec
Reputation Power: 0
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

#4
November 28th, 2012, 10:17 AM
 b49P23TIvg
Contributing User

Join Date: Aug 2011
Posts: 4,214
Time spent in forums: 1 Month 3 Weeks 2 Days 18 h 7 m 36 sec
Reputation Power: 455
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.

 Viewing: Dev Shed Forums > Programming Languages > Python Programming > Something about matrices