numpy array access

You could avoid memory allocation doing :

A[:] = B[:]
A[:] += C[:]

This might yield speed-up, yet it might also not.
The things you have to know :

  • Here, you have to get the memory adresses within the A array to set them to their new values. Depending on the size of A, last time it was accessed, and the computer memories, it might be within the L1 cache, the L3, or the RAM (at some arbitrary heap position). This can drastically influence the memory access latency.
  • Numpy arrays are data structures which are contiguous in memory, while python lists are not.
  • Allocating the space for the new array with A = B + C will still require to access B and C.
  • Unless you have a specific need to re-assign the values in memory, you better keep things simple with numpy and count on external compilation libraries to increase performance and memory management (e.g. numba, numexpr, pythran, jax.jit, cython).