Last active
August 23, 2017 14:03
-
-
Save huangziwei/3803424f3a7ee732162669edca6c1aca to your computer and use it in GitHub Desktop.
porting some some R functions to python
This file contains 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
def lfactorial(n): | |
from scipy.special import gammaln | |
return gammaln(n+1) | |
def lchoose(n, k): | |
from scipy.special import gammaln | |
return (gammaln(n+1) - gammaln(n-k+1) - gammaln(k+1)) | |
def sample(x, size, replace=False, prob=None): | |
import numpy as np | |
if type(x) == int: | |
a = np.arange(1, x+1) | |
else: | |
a = x | |
return np.random.choice(a, size, replace, prob) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment