Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 18789

np.repeat inplace solution to avoid memory reallocation

$
0
0

How can I asign np repeat (or equivalent function) output to existing memory? (many numpy functions have an "out=" parameter to do this). This reasignation would be very useful because I have a (extremely big) previously created array of the same size (as the new one) that I am not using any more through the rest of my program. Reusing its place in memory would allow me to avoid a lot of memory reallocation.

I have tried this. But it does not accelerate the allocation.

diff_bp[:,:,:] = np.repeat(np.linalg.norm(diffs, axis=2)[:, :, None], repeats=d, axis=2)dist_point_vertex = diff_bp

This broadcasting trick accelerates slightly:

diff_bp[:,:,:] = np.linalg.norm(diffs, axis=2)[:,:,None]dist_point_vertex = diff_bp

Still far from fast


Viewing all articles
Browse latest Browse all 18789

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>