import numpy as np
import itertools as it
def use_list(x, length):
c = it.product(x, repeat=length)
return np.array(list(c), dtype=np.complex64)
def use_slicing(x, length):
data = np.empty((len(x)**length, length), dtype=np.complex64)
for i in range(length):
for j in range(len(x)):
data[j::len(x), i] = x[j]
return data
length = 4
x = [np.complex(1,0), np.complex(-1,0),
np.complex(0,1), np.complex(0,-1)]
a = use_list(x, length)
b = use_slicing(x, length)
print a
print b
assert set(map(tuple, a)) == set(map(tuple, b)), 'Differing results!'