matrix 12 13 from Numeric import matrix matrix strip split for line in

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
matrix = """
- 1 4 6 - - - -
- - 1 - 12 - - -
- 1 - 3 - 6 - -
- - 3 - - - 2 -
- - - - - 3 - 2
13 - - - 3 - 2 5
- - - - - 2 - 6
- 2 3 - 4 7 8 -
"""
from Numeric import *
matrix = matrix.strip().split('\n')
for i, line in enumerate(matrix):
matrix[i] = line.split()
for j, item in enumerate(matrix[i]):
if item <> '-':
matrix[i][j] = int(item)
else:
matrix[i][j] = -1
print array(matrix, Int)