使用python生成大型矩阵用于测试程序
from numpy import random
from os import path
#输入a,b,输出一个a*b维的矩阵
a=int(input())
b=int(input())
#filepath为输出矩阵所在文件的路径
#我们把矩阵写入一个文档,而不是在终端输出
filepath="文件路径"
f=open(filepath,'w+')
f.write(str(a)+' '+str(b)+'\n')
arr=random.randint(0,100,size=(a,b))#矩阵中元素大小在0-100之间
for x in arr:
#用空格将各个元素分隔开,也可以改为“,”
f.write((' ').join(str(y) for y in x)+'\n')
f.close()
比如我们在控制台/终端输入:
10
10
输出的文件: