(matrix)
| 6 | ''' |
| 7 | from numpy import * |
| 8 | def sparseToTriple(matrix): |
| 9 | m, n = shape(matrix) |
| 10 | triple = [] |
| 11 | for i in range(m): |
| 12 | for j in range(n): |
| 13 | if matrix[i][j] != 0: |
| 14 | triple.append([i, j, matrix[i][j]]) |
| 15 | return triple |
| 16 | |
| 17 | def transTriple(triple): |
| 18 | m, n = shape(triple) |