Sometimes is useful to assign arrays with one index only. In Matlab this is straightforward:
M = zeros(4); M(1:5:end) = 1 M = 1 0 0 0 0 1 0
Another way using unravel_index
>>> M = zeros((4,4)); >>> M[unravel_index(arange(0,4*4,5),(4,4))]= 1 >>> M array([[ 1., 0., 0., 0.], [ 0., 1., 0., 0.], [ 0., 0., 1., 0.], [ 0., 0., 0., 1.]])