Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
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:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old June 30th, 2003, 04:23 PM
shochu shochu is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 6 shochu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Creating large arrays

I wanted to create an array to store the data I have from an image file. Being that they are medical images they are quite large (anywhere from 35mb to 600 mb)

I tried doing the following but it just crashes

for i in range(0, arraySize):
myArray.append(0)

I need to create an array just filled with zeros the proper size so that I can run the array through a filter that will put in the actual values.

Doing the above crashes if I make the arraySize too large. (ie. over 1,000,000) I need arrays at least 18 million large.

The strange thing is this worked when I did myArray.fromfile() and just streamed the entire binary into the array.

Is this a limit of python and I need to figure out how to do it some other way or am I programming it wrong? Thank you for any help.

(PS: I have 2 gigs of memory so it's not filling that up)

Reply With Quote
  #2  
Old June 30th, 2003, 06:03 PM
netytan's Avatar
netytan netytan is offline
Hello World :)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Mar 2003
Location: Hull, UK
Posts: 2,529 netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 17 h 19 m 5 sec
Reputation Power: 63
Send a message via ICQ to netytan Send a message via AIM to netytan Send a message via MSN to netytan Send a message via Yahoo to netytan
Seems to work for me, I'm running the test now and its running through nicely, its very slow but then it is a very high number! Anyway, just wondering why if it worked with fromfile() why your not using it? It seems pretty pointless to rewrite code, plus fromfile is probably faster .

Have fun,
Mark.

Reply With Quote
  #3  
Old June 30th, 2003, 06:35 PM
netytan's Avatar
netytan netytan is offline
Hello World :)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Mar 2003
Location: Hull, UK
Posts: 2,529 netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 17 h 19 m 5 sec
Reputation Power: 63
Send a message via ICQ to netytan Send a message via AIM to netytan Send a message via MSN to netytan Send a message via Yahoo to netytan
Max Iteration

Oh ok, test just finished at 199999! I dont think it's an array size problem, if you can store 18000000 entries with the fromfile() function then it is most likly to do with the loop. Maybe you should try a while loop, i'm not sure whether there is a max number of iterations on this but it's worth a try, or maybe you could try several loops... 18 in fact but thats a really bad way of doing things!

Hope this helps,
Mark.

Reply With Quote
  #4  
Old July 1st, 2003, 09:18 AM
shochu shochu is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 6 shochu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I can't use fromfile because I create the values on the fly. Thus I want to be able to insert them into the array at different indices. Does anyone know of any other way to initialize an array other than appending items?

(fromfile does work much faster but that's not an option)

** This is how to do it for anyone that might have to do this in the future

you want to do the following

a = array('h', myArray = [0] * arraySize)


Where of course the 0 is whatever you want to initialize the array to.

here h is a signed int (2 bytes)

Last edited by shochu : July 11th, 2003 at 09:23 AM.

Reply With Quote
  #5  
Old July 10th, 2003, 06:38 PM
inkedmn inkedmn is offline
Tattooed Python-Lovin' Freak-Boy
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2001
Location: orange county, CA
Posts: 16 inkedmn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to inkedmn Send a message via AIM to inkedmn
Code:
arraysize = 18000000
mylist = range(arraysize)

that will give you an array of 18,000,000 elements (just numbers) that you can iterate through, etc.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Creating large arrays


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 | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway