Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I'd probably use SparseArrays here (<strong>see update below</strong>), but if you insist on using functions and *Values to store and retrieve values an approach would be to have the first part (f[2] etc.) replaced by a symbol you create on the fly like:</p> <pre><code>Table[Symbol["f" &lt;&gt; IntegerString[i, 10, 3]], {i, 11}] (* ==&gt; {f001, f002, f003, f004, f005, f006, f007, f008, f009, f010, f011} *) Symbol["f" &lt;&gt; IntegerString[56, 10, 3]] (* ==&gt; f056 *) Symbol["f" &lt;&gt; IntegerString[56, 10, 3]][{3, 4}] = 12; Symbol["f" &lt;&gt; IntegerString[56, 10, 3]][{23, 18}] = 12; Symbol["f" &lt;&gt; IntegerString[56, 10, 3]] // Evaluate // DownValues (* ==&gt; {HoldPattern[f056[{3, 4}]] :&gt; 12, HoldPattern[f056[{23, 18}]] :&gt; 12} *) f056 // DownValues (* ==&gt; {HoldPattern[f056[{3, 4}]] :&gt; 12, HoldPattern[f056[{23, 18}]] :&gt; 12} *) </code></pre> <p>Personally I prefer Leonid's solution, as it's much more elegant but YMMV.</p> <p><strong>Update</strong></p> <p>On OP's request, about using <code>SparseArrays</code>:<br> Large SparseArrays take up a fraction of the size of standard nested lists. We can make f to be a large (100,000 entires) sparse array of sparse arrays:</p> <pre><code>f = SparseArray[{_} -&gt; 0, 100000]; f // ByteCount (* ==&gt; 672 *) (* initialize f with sparse arrays, takes a few seconds with f this large *) Do[ f[[i]] = SparseArray[{_} -&gt; 0, {100, 110}], {i,100000}] // Timing//First (* ==&gt; 18.923 *) (* this takes about 2.5% of the memory that a normal array would take: *) f // ByteCount (* ==&gt; 108000040 *) ConstantArray[0, {100000, 100, 100}] // ByteCount (* ==&gt; 4000000176 *) (* counting phase *) f[[1]][[1, 2]]++; f[[1]][[1, 2]]++; f[[1]][[42, 64]]++; f[[2]][[100, 11]]++; (* reporting phase *) f[[1]] // ArrayRules f[[2]] // ArrayRules f // ArrayRules (* ==&gt;{{1, 2} -&gt; 2, {42, 64} -&gt; 1, {_, _} -&gt; 0} ==&gt;{{100, 11} -&gt; 1, {_, _} -&gt; 0} ==&gt;{{1, 1, 2} -&gt; 2, {1, 42, 64} -&gt; 1, {2, 100, 11} -&gt; 1, {_, _, _} -&gt; 0} *) </code></pre> <p>As you can see, <code>ArrayRules</code> makes a nice list with contributions and counts. This can be done for each f[i] separately or the whole bunch together (last line).</p>
 

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