iters = 1000
S = np.repeat(list(itertools.product([-1, 1], repeat=n + 1)), iters, axis=0
    ).reshape((-1, n + 1))
F = np.random.choice(np.array([-1, 0, 0, 1], dtype=np.int8), size=(iters * 
    2 ** (n + 2), n))
F = F[~(F == 0).all(1)][:iters * 2 ** (n + 1)]
FS = np.asanyarray(map(lambda x, y: np.convolve(x, y, 'valid'), F, S))
firstzero = (FS[:, (0)] == 0).sum()
bothzero = (FS == 0).all(1).sum()
print('firstzero', firstzero)
print('bothzero', bothzero)
How to speed up numpy code