8000 np.random.choice without replacement or weights is less efficient than random.sample? · Issue #2764 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content
np.random.choice without replacement or weights is less efficient than random.sample? #2764
Closed
@yoavram

Description

@yoavram

I was interested in choosing k elements out of n without replacement or weighted probabilities, and with k<<n.

I've tested using the following ipython notebook: source / view.

The outcome was that using random.sample(xrange(n),k) was ~50-fold faster than using np.random.permutation(n)[:k], which is the way it is currently coded.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0