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