How to to read a matrix from a given file?

前端 未结 7 670
傲寒
傲寒 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:23

    Check out this small one line code for reading matrix,

    matrix = [[input() for x in range(3)] for y in range(3)]
    

    this code will read matrix of order 3*3.

提交回复
热议问题