Mercurial > hg > nsaunier > traffic-intelligence
comparison python/utils.py @ 841:90b7d6e19c55
minor
| author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
|---|---|
| date | Mon, 11 Jul 2016 17:46:00 -0400 |
| parents | 15a82ebc62c4 |
| children | 36c5bee9a887 |
comparison
equal
deleted
inserted
replaced
| 840:15a82ebc62c4 | 841:90b7d6e19c55 |
|---|---|
| 482 table2['Variables'] = [var for var in result if data.dtypes[var] != dtype('O')] | 482 table2['Variables'] = [var for var in result if data.dtypes[var] != dtype('O')] |
| 483 out.write(DataFrame(table2)[['Variables', 'Correlations', 'Valeurs p']].to_html(formatters = {'Correlations': lambda x: '{:.2f}'.format(x), 'Valeurs p': lambda x: '{:.3f}'.format(x)}, index = False)) | 483 out.write(DataFrame(table2)[['Variables', 'Correlations', 'Valeurs p']].to_html(formatters = {'Correlations': lambda x: '{:.2f}'.format(x), 'Valeurs p': lambda x: '{:.3f}'.format(x)}, index = False)) |
| 484 out.close() | 484 out.close() |
| 485 return result | 485 return result |
| 486 | 486 |
| 487 def saveDokMatrix(filename, m): | 487 def saveDokMatrix(filename, m, lowerTriangle = False): |
| 488 'Saves a dok_matrix using savez' | 488 'Saves a dok_matrix using savez' |
| 489 savez(filename, shape = m.shape, keys = m.keys(), values = m.values()) | 489 if lowerTriangle: |
| 490 keys = [k for k in m.keys() if k[0] > k[1]] | |
| 491 savez(filename, shape = m.shape, keys = keys, values = [m[k[0],k[1]] for k in keys]) | |
| 492 else: | |
| 493 savez(filename, shape = m.shape, keys = m.keys(), values = m.values()) | |
| 490 | 494 |
| 491 def loadDokMatrix(filename): | 495 def loadDokMatrix(filename): |
| 492 'Loads a dok_matrix saved using the above saveDokMatrix' | 496 'Loads a dok_matrix saved using the above saveDokMatrix' |
| 493 data = npload(filename) | 497 data = npload(filename) |
| 494 m = dok_matrix(tuple(data['shape'])) | 498 m = dok_matrix(tuple(data['shape'])) |
