I am looking for an equivalent of np.choice into an already existing array, so that I can just calculate numbers into some memory buffer in chunks, instead of allocating it.
Answer should be something like
import numpy as np
low, high = 0, 10
space = np.linspace(start=low, stop=high, num=1000)
rng = np.random.default_rng()
buffer = np.zeros((n,))
rng.choice(space, size=n, replace=False, target=buffer)
I expect buffer to have the data in the end, and not have more memory allocated.
Aucun commentaire:
Enregistrer un commentaire