The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> Python Programming
|
Something about matrices
Discuss Something about matrices in the Python Programming forum on Dev Shed. Something about matrices Python Programming forum discussing coding techniques, tips and tricks, and Zope related information. Python was designed from the ground up to be a completely object-oriented programming language.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

November 22nd, 2012, 10:41 AM
|
|
Registered User
|
|
Join Date: Nov 2012
Posts: 13
Time spent in forums: 3 h 21 m 37 sec
Reputation Power: 0
|
|
|
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 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 
|

November 23rd, 2012, 09:51 AM
|
 |
Contributing User
|
|
|
|
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!
|

November 28th, 2012, 08:59 AM
|
|
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 
|

November 28th, 2012, 09:17 AM
|
 |
Contributing User
|
|
|
|
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.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|