dimanche 7 août 2022

Replicating MATLAB's `randperm` in NumPy

I want to replicate MATLAB's randperm() with NumPy.

Currently, to get randperm(n, k) I use np.random.permutation(n)[:k]. The problem is it allocates an array of size n then takes only k entries of it.

Is there a more memory efficient way to directly create the array?




Aucun commentaire:

Enregistrer un commentaire