numpy array access

For both C = A * B and C[:] = A * B the product of A and B is calculated and a new object is constructed. A faster approach is to use the numpy inplace operations (assuming the array C can be pre-allocated). Benchmark:

import numpy as np
rng = np.random.default_rng(123)

n = 16_000_000
A = rng.random(n)
B = rng.random(n)
C = np.empty_like(A) 

%timeit C = A * B
%timeit C[:] = A * B 
%timeit np.multiply(A, B, C)

results in:

35.7 ms ± 173 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)
47.7 ms ± 186 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)
27.7 ms ± 92.9 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)

If overwriting the contents of A is possible, then A *= B is also a fast option (about 21 ms).