usr bin env python import numpy for line in open matrix txt append flo

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
#!/usr/bin/env python
import numpy
l = []
for line in open( 'matrix.txt' ):
l.append( [ float(x) for x in line.split() ] )
m = numpy.matrix( l )
print m
Result:
[[ 4. 0.68 0.98 0.23]
[ 4. 0.23 0.54 0.32]
[ 5. 0.56 0.12 0.99]]