Matrix Market 矩阵数据文件交换格式、读写函数

Matrix Market 官方主页

主流稀疏和稠密矩阵数据文件交换格式


读写接口

HB格式资料

小工具

用scipy.io中的mminfo&mmread检查Matrix Market文件有效性

#!/bin/python3
'''
Validate Matrix Market format(MTX) file by using scipy.io.mminfo & scip.io.mmread 
'''

import sys
import os

#https://www.geeksforgeeks.org/how-to-print-exception-stack-trace-in-python/
import traceback 

from scipy.io import mminfo,mmread,mmwrite

def usage():
    print('''Usage:  /mtx_check.py  <MTX-FILE>''');
    
if len(sys.argv)!=2:
    usage()
    exit(1)

mtx_file=sys.argv[1];

if not(os.path.isfile(mtx_file)):
    print('{} is not a file'.format(mtx_file))
    usage()
    exit(2)

try:
    mminfo(mtx_file)
except:
    print('{} mminfo failed'.format(mtx_file))
    
    #https://pythonsolved.com/python-get-first-line-of-file/
    with open(mtx_file,'r') as f:
    	first_line=f.readline()
    	print('{} first line: "{}"'.format(mtx_file,first_line.rstrip('\n')))
    
    traceback.print_exc()
    
    exit(3)
else:
    print('{} mminfo OK!'.format(mtx_file))

try:
    A=mmread(mtx_file)
except:
    print('{} mmread failed'.format(mtx_file))
    
    traceback.print_exc()
    
    exit(4)
else:
    print('{} mmread OK!'.format(mtx_file))

exit(0)

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值