Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>@Jeff</p> <p>I actually think this is an interesting question. I'm not sure how useful it is, but it is a valid question.</p> <p>@Ed</p> <p>Can you provide a little more info on this question? You said the dimension of the array is dynamic, but is the number of elements dynamic as well?</p> <p>EDIT: I'm going to try and answer the question anyways. I can't give you the code off the top of my head (it would take a while to get it right without any compiler here on this PC), but I can point you in the right direction ...</p> <p>Let's use 8 dimensions (0-7) with indexes 0 to 3 as an example. You care about only 1,2 and 6. This means you have two arrays. First, <code>array_care[4][4][4]</code> for 1,2, and 6. The <code>array_care[4][4][4]</code> will hold the end result.</p> <p>Next, we want to iterate in a very specific way. We have the array <code>input[4][4][4][4][4][4][4][4]</code> to parse through, and we care about dimensions 1, 2, and 6.</p> <p>We need to define some temporary indexes:</p> <pre><code>int dim[8] = {0,0,0,0,0,0,0,0}; </code></pre> <p>We also need to store the order in which we want to increase the indexes:</p> <pre><code>int increase_index_order[8] = {7,5,4,3,0,6,2,1}; int i = 0; </code></pre> <p>This order is important for doing what you requested.</p> <p>Define a termination flag:</p> <pre><code>bool terminate=false; </code></pre> <p>Now we can create our loop:</p> <pre><code>while (terminate) { array_care[dim[1]][dim[2]][dim[6]] += input[dim[0]][dim[1]][dim[2]][dim[3]][dim[4]][dim[5]][dim[6]][dim[7]]; while ((dim[increase_index_order[i]] = 3) &amp;&amp; (i &lt; 8)) { dim[increase_index_order[i]]=0; i++; } if (i &lt; 8) { dim[increase_index_order[i]]++; i=0; } else { terminate=true; } } </code></pre> <p>That should work for 8 dimensions, caring about 3 dimensions. It would take a bit more time to make it dynamic, and I don't have the time. Hope this helps. I apologize, but I haven't learned the code markups yet. :(</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