In [2]:
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline

In [9]:
r = np.random.ranf((4,))
p = np.fromfunction(lambda x: x % 4, (8,), dtype=int)
np.random.shuffle(p)


Out[9]:
array([0, 1, 1, 3, 0, 3, 2, 2], dtype=int32)

In [11]:
def h(x, y, z):
    return p[p[x + y] + z]

[[[h(x, y, z) for x in range(4)] for y in range(4)] for z in range(4)]


Out[11]:
[[[0, 1, 1, 3], [1, 1, 3, 0], [1, 3, 0, 3], [3, 0, 3, 1]],
 [[1, 1, 1, 0], [1, 1, 0, 1], [1, 0, 1, 0], [0, 1, 0, 3]],
 [[1, 3, 3, 3], [3, 3, 3, 1], [3, 3, 1, 3], [3, 1, 3, 0]],
 [[3, 0, 0, 2], [0, 0, 2, 3], [0, 2, 3, 2], [2, 3, 2, 3]]]

In [ ]: