example_countries.py 文件源码

python
阅读 17 收藏 0 点赞 0 评论 0

项目:mrqap-python 作者: lisette-espin 项目源码 文件源码
def getMatrix(path, directed=False, log1p=False):
    matrix = np.zeros(shape=(NCOUNTRIES,NCOUNTRIES))
    with open(path, 'rb') as f:
        for line in f:
            data = line.split(' ')
            c1 = int(data[0])-1
            c2 = int(data[1])-1
            v = np.log1p(float(data[2])) if log1p else float(data[2])
            matrix[c1][c2] = v # real data from file
            if not DIRECTED:
                matrix[c2][c1] = v # symmetry
    print '{} loaded as a matrix!'.format(path)
    return matrix

#######################################################################
# Data Matrices
#######################################################################
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号