Row-normalize sparse matrix
(mx)
| 932 | |
| 933 | |
| 934 | def _normalize(mx): |
| 935 | """Row-normalize sparse matrix""" |
| 936 | rowsum = np.asarray(mx.sum(1)) |
| 937 | mask = np.equal(rowsum, 0.0).flatten() |
| 938 | rowsum[mask] = np.nan |
| 939 | r_inv = np.power(rowsum, -1).flatten() |
| 940 | r_inv[mask] = 0.0 |
| 941 | r_mat_inv = sp.diags(r_inv) |
| 942 | return r_mat_inv.dot(mx) |
| 943 | |
| 944 | |
| 945 | def _encode_onehot(labels): |
no test coverage detected