Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sample_without_replacement refactored #196

Merged
merged 1 commit into from
Sep 19, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions quantecon/random/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,16 +124,14 @@ def sample_without_replacement(n, k, num_trials=None, random_state=None):

# Logic taken from random.sample in the standard library
result = np.empty((m, k), dtype=int)
pool = np.empty((m, n), dtype=int)
pool = np.empty(n, dtype=int)
for i in range(m):
for j in range(n):
pool[i, j] = j

for i in range(m):
pool[j] = j
for j in range(k):
idx = int(np.floor(r[i, j] * (n-j))) # np.floor returns a float
result[i, j] = pool[i, idx]
pool[i, idx] = pool[i, n-j-1]
result[i, j] = pool[idx]
pool[idx] = pool[n-j-1]

if num_trials is None:
return result[0]
Expand Down