Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 22nd, 2012, 10:41 AM
giacomo84 giacomo84 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 13 giacomo84 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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

Reply With Quote
  #2  
Old November 23rd, 2012, 09:51 AM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is offline
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,357 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 3 Days 9 h 10 m 17 sec
Reputation Power: 383
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!

Reply With Quote
  #3  
Old November 28th, 2012, 08:59 AM
giacomo84 giacomo84 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 13 giacomo84 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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

Reply With Quote
  #4  
Old November 28th, 2012, 09:17 AM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is offline
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,357 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 3 Days 9 h 10 m 17 sec
Reputation Power: 383
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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Something about matrices

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

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


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap