MCPcopy
hub / github.com/dmlc/dgl / _normalize

Function _normalize

python/dgl/data/citation_graph.py:934–942  ·  view source on GitHub ↗

Row-normalize sparse matrix

(mx)

Source from the content-addressed store, hash-verified

932
933
934def _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
945def _encode_onehot(labels):

Callers 1

_preprocess_featuresFunction · 0.85

Calls 1

flattenMethod · 0.80

Tested by

no test coverage detected