Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>As a matter of fact, your program needs at least(!) 300*300*300*4*3 bytes solely for the value data of the dicts. Besides, your key tuples occupy 300*300*300*3*3*4 bytes.</p> <p>This is in total 1296000000 bytes, or 1.2 GiB of data.</p> <p>This calculation doesn't even include the overhead of maintaining the data in the dict.</p> <p>So it depends on the amount of memory which your machine has if it fails or not.</p> <p>You could do a first step and do</p> <pre><code>s = {} ns = {} ts = {} for i in range(0, 300): for j in range(0, 300): for k in range(0, 300): index=(i, j, k) s[index]=j ns[index]=k ts[index]=i*j*k </code></pre> <p>which (in theory) will only occupy half the memory as before - as well, only for the data, as the index tuples are reused.</p> <hr> <p>From what you describe (you want a mere counting), you don't need the full range of combinations to be pre-initialized. So you can omit your initialization shown in the question and instead build a storage where you only store these values where you actually have data, which are supposedly much fewer than possible.</p> <p>You either could use a <a href="http://docs.python.org/library/collections.html#defaultdict-objects" rel="nofollow"><code>defaultdict()</code></a> or imitate its behavoiur manually, as I think that most of the combinations are not used in your color "palette".</p> <pre><code>from collections import defaultdict make0 = lambda: 0 s = defaultdict(make0) ns = defaultdict(make0) # what is ts? do you need it? </code></pre> <p>Now you have three <code>dict</code>-like objects which can be written to if needed. Then, for every combination of colors which you really have, you can do <code>s[index] += 1</code> resp. <code>ns[index] += 1</code>.</p> <p>I don't know about your <code>ts</code> - maybe you either can calculate it, or you'll have to find a different solution.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload