Created
June 8, 2020 05:44
-
-
Save binshengliu/be4ddca30101ff3879cb2dbfe9ff937a to your computer and use it in GitHub Desktop.
Random choice unique along axis
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # https://stackoverflow.com/a/45438143/955952 | |
| def random_choice_noreplace(m, n, axis=-1): | |
| # m, n are the number of rows, cols of output | |
| return np.random.rand(m, n).argsort(axis=axis) |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use torch.multinomial for multiple independent sampling with probabilities.
Output: