I want to create a 1D array that consists of alternating sets of ones and zeros defined by two input arrays. For example:
import numpy as np
In1 = np.array([2, 1, 3])
In2 = np.array([1, 1, 2])
Out1 = np.array([])
for idx in range(In1.size):
Ones = np.ones(In1[idx])
Zeros = np.zeros(In2[idx])
Out1 = np.concatenate((Out1, Ones, Zeros))
print(Out1)
array([1., 1., 0., 1., 0., 1., 1., 1., 0., 0.])
Is there a more efficient way to do this that doesn't use a for loop?