python - numpy: boolean indexing and memory usage -
consider following numpy
code:
a[start:end] = b[mask]
here:
a
,b
2d arrays same number of columns;start
,end
scalars;mask
1d boolean array;(end - start) == sum(mask)
.
in principle, above operation can carried out using o(1)
temporary storage, copying elements of b
directly a
.
is happens in practice, or numpy
construct temporary array b[mask]
? if latter, there way avoid rewriting statement?
using boolean arrays index fancy indexing, numpy needs make copy. write cython extension deal it, if getting memory problems.
Comments
Post a Comment