python alist_Python处理alist文件——稀疏矩阵的读取和存储

众所周知,alist文件是一种保存稀疏矩阵格式,常用于保存LDPC码的校验矩阵与生成矩阵。

Matrix File Formats - TU Kaiserslautern提供了一个信道编码的数据库,并给出了数据库中信道编码的校验矩阵的存储方法和格式。

这种格式也见于alist format

Database of Channel Codes and ML Simulation Results从这里可以下载校验矩阵的alist文件。

读取alist文件中保存的矩阵,将稀疏矩阵保存为alist格式,有以下三种python方案(其中前两种,矩阵的行和列设定是一致的):

要注意的是,可能保存或读写的是想获得的稀疏矩阵的转置,在应用以上的脚本时,根据自己的需要和判断,决定加不加.T

最适合Matrix File Formats - TU Kaiserslautern的python实现

import numpy as np

# 校验矩阵的读取

def alistToNumpy(lines):

"""Converts a parity-check matrix in AList format to a 0/1 numpy array. The argument is a

list-of-lists corresponding to the lines of the AList format, already parsed to integers

if read from a text file.

The AList format is introduced on http://www.inference.phy.cam.ac.uk/mackay/codes/alist.html.

This

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值