[Tutor] Memory error for list creation

2010-08-24 Thread Triantafyllos Gkikopoulos
Hi,
 
 I am looking for an alternative to:
 


Please consider the environment. Do you really need to print this email? 


 
 listx=[[[] for k in range(ds)] for j in range(i)]
 
as right now I am getting a Memory error on this, I tried this also on a 
cluster node with something like 16GB of memory and it didn't solve the problem.
 
listx is subsequently used:
 
 for x in something:
  for y in x:
   listx[ii][y[1]].append(y[0])
  ii+=1
 
 
 
 For reference values for k range from 300 -1200 and for i ~5000.
 
 
I though about using scipy/numpy array but then I wouldn't be able to have the 
flexibility of using append or not having to predefine the size.
 
 
 Thanks
 

The University of Dundee is a registered Scottish charity, No: SC015096
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] casting string to integer in a list of lists

2009-01-09 Thread Triantafyllos Gkikopoulos
Hi Your,

 I work with genomic datasets as well and have recently only started working 
with python (so my advice is a bit naive)

 I would say although there may be different ways you can cast an integer or 
float type into your list of lists you may actually no need to do so with your 
starting file/list... ie:

 if for example you want to do stuff with the location chrX with start 
160944034 and end 160944035

 you could: 
for x in LoL:
startstring=LoL[1]  #this would be '160944034'
startint=int(startstring) #this would be 160944034

now if you also use a counter you can iterate and do all sort of calculations 
for different genomic locations.

 I use the csv module and then append into a numpy array that takes type float, 
so you could work with that as well,

cheers
  

Dr Triantafyllos Gkikopoulos
 culpritNr1 ig2ar-s...@yahoo.co.uk 01/08/09 8:42 PM 

Hi All,

Say I have this nice list of lists:

LoL = [['chrX', '160944034', '160944035', 'gnfX.145.788', '63.60'],
 ['chrX', '161109992', '161109993', 'rs13484104', '63.60'],
 ['chrX', '161414112', '161414113', 'rs13484105', '63.60'],
 ['chrX', '161544071', '161544072', 'rs13484106', '63.60'],
 ['chrX', '162030736', '162030737', 'gnfX.146.867', '67.05'],
 ['chrX', '164171913', '164171914', 'gnfX.148.995', '70.45']]

Now I want to cast the second and third columns from string to integer,
like this

LoL = [['chrX', 160944034, 160944035, 'gnfX.145.788', '63.60'],
 ['chrX', 161109992, 161109993, 'rs13484104', '63.60'],
 ['chrX', 161414112, 161414113, 'rs13484105', '63.60'],
 ['chrX', 161544071, 161544072, 'rs13484106', '63.60'],
 ['chrX', 162030736, 162030737, 'gnfX.146.867', '67.05'],
 ['chrX', 164171913, 164171914, 'gnfX.148.995', '70.45']]

Is there any elegant way to do this? I can't assume that all lines will have
the same number of elements.

Thank you,

Your Culprit


-- 
View this message in context: 
http://www.nabble.com/casting-string-to-integer-in-a-list-of-lists-tp21359600p21359600.html
Sent from the Python - tutor mailing list archive at Nabble.com.

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

The University of Dundee is a registered Scottish charity, No: SC015096
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor