Issue
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?
Solution
I can recommend you np.random.choice(n, k, replace = False)
.
Yet, I am not sure about memory efficiency.
Please refer to docs
Answered By - TaQ
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.