How to produce the following three dimensional array?
<p>I have a cube of size <code>N * N * N</code>, say <code>N=8</code>. Each dimension of the cube is discretised to 1, so that I have labelled points <code>(0,0,0), (0,0,1)..(N,N,N)</code>. At each labelled points, I would like to assign a random value, and thus produce an array which stores value at each vertex. For example <code>val[0,0,0]=1, val[0,0,1]=1.2 val[0,1,0]=1.3</code>, ...</p>

<p>How do I write a python code to acheive this?</p>

<p>You could simply generate lists of lists. While not in any way efficient, it would allow you to access your cube like <code>val[0][0][0]</code>.</p>

<pre><code>arr = [[[] for _ in range(8)] for _ in range(8)]

arr[0][0].append(1)
</code></pre>

python arrays python-2.7