Consider the following numpy
code:
A[start:end] = B[mask]
Here:
A
andB
are 2D arrays with the same number of columns;start
andend
are scalars;mask
is a 1D boolean array;(end - start) == sum(mask)
.
In principle, the above operation can be carried out using O(1)
temporary storage, by copying elements of B
directly into A
.
Is this what actually happens in practice, or does numpy
construct a temporary array for B[mask]
? If the latter, is there a way to avoid this by rewriting the statement?