Given a ndarray of size (n, 3) with n around 1000, how to multiply together all elements for each row, fast? The (inelegant) second solution below
(n, 3)
n
np.prod accepts an axis argument:
np.prod
np.prod(a, axis=1)
With axis=1, the column-wise product is computed for each row.
axis=1
Sanity check
assert np.array_equal(np.prod(a, axis=1), prod1(a))
Performance
17.6 µs ± 146 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)
(1000x speedup)