data_io.py 文件源码

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

项目:AutoML5 作者: djajetic 项目源码 文件源码
def data_binary_sparse (filename, nbr_features):    
    ''' This function takes as an argument a file representing a binary sparse matrix
    binary_sparse_matrix[i][j] = a means matrix[i][j] = 1
    It converts it into a numpy array an returns this array. '''

    data = data_converter.file_to_array (filename)
    nbr_samples = len(data)
    dok_sparse = dok_matrix ((nbr_samples, nbr_features)) # the construction is easier w/ dok_sparse
    print ("Converting {} to dok sparse matrix".format(filename))
    for row in range (nbr_samples):
        for feature in data[row]:
            dok_sparse[row, int(feature)-1] = 1
    print ("Converting {} to csr sparse matrix".format(filename))
    return dok_sparse.tocsr()

# ================ Copy results from input to output ==========================
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号