Matrix input from a text file(python 3)
Question: Im trying to find a way to be able to input a matrix from a text file;

for example, a text file would contain

    
    
    1 2 3
    4 5 6
    7 8 9
    

And it would make a matrix with those numbers and put it in matrix =
[[1,2,3],[4,5,6],[7,8,9]]

And then this has to be compatible with the way I print the matrix:

    
    
     print('\n'.join([' '.join(map(str, row)) for row in matrix]))
    

So far,I tried this

chemin = input('entrez le chemin du fichier')

    
    
            path = input('enter file location') 
    
            f = open ( path , 'r')
            matrix = [ map(int,line.split(','))) for line in f if line.strip() != "" ]
    

All it does is return me a map object and return an error when I try to print
the matrix.

What am I doing wrong? Matrix should contain the matrix read from the text
file and not map object,and **I dont want to use external library such as
numpy**

Thanks


Answer: As explained in
[numpy.genfromtxt()](http://docs.scipy.org/doc/numpy/user/basics.io.genfromtxt.html):

    
    
    import StringIO, numpy
    data = "1 2 3\n4 5 6\n7 8 9"
    numpy.genfromtxt(StringIO.StringIO(data), delimiter = ' ')
    
    > array([[ 1.,  2.,  3.],                                                  
           [ 4.,  5.,  6.],                                                  
           [ 7.,  8.,  9.]])
    

Take two:

    
    
    [list(map(int, line.split(' '))) for line in data.split('\n')]
    > [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
    

