How to to read a matrix from a given file?

前端 未结 7 672
傲寒
傲寒 2020-12-09 17:41

I have a text file which contains matrix of N * M dimensions.

For example the input.txt file contains the following:



        
7条回答
  •  长情又很酷
    2020-12-09 18:01

    You can do this:

    fin = open('input.txt','r')
    a=[]
    for line in fin.readlines():
        a.append( [ int (x) for x in line.split(',') ] )
    

提交回复
热议问题