Dustone
2021/5/12
本文为深度概率模型采样库pydpm中Topic model的matlab代码转Python代码时总结的细节及注意事项
宣传一下实验室的pydpm库:https://github.com/BoChenGroup/pydpm
函数替换m -> py
浮点数精度 eps -> np.spacing(1)
矩阵A*B -> np.dot(A,B)
A.*B -> A*B
randi(max,m,n) -> np.random.randint(max,size=(m,n))
A./sum(A,2) -> A/A.sum(axis=1,keepdims=1) # A为矩阵/ndarray
randg -> np.random.gamma
betarnd -> np.random.beta
x(find(x>0))=0 -> np.argwhere(x>t) 返回每个元素的索引
x[x>0]=0 x>0返回布尔值
np.where(a==1) 返回维数个array构成的tuple,array为元素的在某维下索引
max(array, realmin) -> np.maximum(array, realmin)
[row,col] = find(X, ...) -> col, row = np.where(X.T) matlab中一列一列地查找,Python中一行一行查找
reshape(X,m,n) -> X.reshape(m,n) 同find用法,matlab按列操作
repmat(x,m