[Tutor] changing 2x3 matrix to 3x2 matrix - using lists
Srinivas Iyyer
srini_iyyer_bio at yahoo.com
Fri Apr 14 23:46:32 CEST 2006
Dear group,
I have a huge list of data. This was obtained using R
through Rpy.
the data resembles a 10K (row) x 30 (column) matrix.
I processed the data column wise( obtained median
values for duplicated rows).
Now I am left with 500 rows and 30 columns.
I want to print the same way.
A snippet:
>>> a = """apple\tboy\tcat\ndog\tegg\tfox\n"""
>>> ab = a.split('\n')
>>> for m in ab:
cols = m.split('\t')
print cols
['apple', 'boy', 'cat']
['dog', 'egg', 'fox']
########################################
# Here I processed the data and assuming nothing
changed in the snippet, I want to print :
##
apple dog
boy egg
cat fox
How can I do that?
I tries a different way below. If there are two lists,
I could use 'zip' method. However, since script is
running over a loop of 30 columns, I have no clue how
can I use zip dynamically.
###################################
>>> for m in result:
for i in range(len(m)):
print m[i]+'\t'+m[i+1]
apple dog
Traceback (most recent call last):
File "<pyshell#80>", line 3, in -toplevel-
print m[i]+'\t'+m[i+1]
IndexError: list index out of range
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
More information about the Tutor
mailing list