Axis walking


In [2]:
%pylab inline
import numpy as np
import ndap
reload(ndap)
subject = np.ones((3,4,5))
plotter = ndap.NDArrayPlotter(subject)
(fig, ax) = plotter.render(azim=-45)


Populating the interactive namespace from numpy and matplotlib

In [30]:
subject = np.ones((3,4,5))

axis = 0                      # Axis to use for inner-loop
ndim = subject.ndim-1         # Number of dimensions in array

shape = [0]*ndim
other_dim = 0
for dim in xrange(subject.ndim):
    if dim == axis:
        continue
    shape[other_dim] = subject.shape[dim]
    other_dim += 1

nelements = 1                 # How many elements are there
for dim in xrange(ndim):
    nelements *= shape[dim]

weight = [0]*ndim     # "weight" of each dimension
acc = 1
for dim in range(0, ndim)[::-1]:
    weight[dim] = acc
    acc *= shape[dim]

eidx = 0
while(eidx<nelements):
    coord = [0]*ndim
    for dim in xrange(0, ndim):
        coord[dim] = (eidx / weight[dim]) % shape[dim]
    print coord
    eidx +=1
    
print axis, ndim, shape, nelements, weight, nchunks, chunksize


[0, 0]
[0, 1]
[0, 2]
[0, 3]
[0, 4]
[1, 0]
[1, 1]
[1, 2]
[1, 3]
[1, 4]
[2, 0]
[2, 1]
[2, 2]
[2, 3]
[2, 4]
[3, 0]
[3, 1]
[3, 2]
[3, 3]
[3, 4]
0 2 [4, 5] 20 [5, 1] 2 5

In [11]:


In [ ]: