![](https://secure.gravatar.com/avatar/0b7d465c9e16b93623fd6926775b91eb.jpg?s=120&d=mm&r=g)
20 May
2021
20 May
'21
2:45 p.m.
This seems like something that can be done with indexing, but I haven't found the solution. out is a 2D array is initialized to zeros. x is a 1D array whose values correspond to the columns of out. For each row in out, set out[row,x[row]] = 1. Here is working code: def orthogonal_mod (x, nbits): out = np.zeros ((len(x), 1<<nbits), dtype=complex) for e in range (len (x)): out[e,x[e]] = 1 return out Any idea to do this without an explicit python loop? -- Those who don't understand recursion are doomed to repeat it