arr_i = np.array(list(product(list(range(r)), repeat=n)))
arr_j = np.array(list(product(list(range(c)), repeat=n)))
Numpy/Python: Efficient matrix as multiplication of cartesian product of input matrix