From b1df00c215ebd4c328d977d694e80b0c64b4fde1 Mon Sep 17 00:00:00 2001 From: Martin Fleischmann Date: Fri, 22 Dec 2023 22:31:50 +0100 Subject: [PATCH] set_self_weights --- libpysal/graph/base.py | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/libpysal/graph/base.py b/libpysal/graph/base.py index e0a39ab8d..e9095d035 100644 --- a/libpysal/graph/base.py +++ b/libpysal/graph/base.py @@ -1421,24 +1421,23 @@ def eliminate_zeros(self): zeros = (self._adjacency == 0) != isolates return Graph(self._adjacency[~zeros], is_sorted=True) - def fill_diagonal(self, val=1): - """Fill Graph with values inserted along the main diagonal. + def set_self_weights(self, val=1): + """Set self-weights in the Graph to a value. Value for each ``focal == neighbor`` location in the graph is set to ``val``. Parameters ---------- val : float | array-like - Defines the value(s) to which the weights matrix diagonal should - be set. If a constant is passed then each element along the - diagonal will get this value (default is 1). An array of length - Graph.n can be passed to set explicit values to each element along - the diagonal (assumed to be in the same order as original data). + Defines the value(s) to which the self-weights should be set. If a constant + is passed then each self-weight will get this value (default is 1). An array + of length ``Graph.n``can be passed to set explicit values to each + self-weight (assumed to be in the same order as original data). Returns ------- Graph - A new Graph with new values along the diagonal + A new Graph with self-weights set """ addition = pd.Series( val, @@ -1454,12 +1453,6 @@ def fill_diagonal(self, val=1): ) return Graph(adj, is_sorted=True) - def fill_diagonal_sparse(self): - sp = self.sparse - sp = sp.tolil() - sp.setdiag(1) - return Graph.from_sparse(sp, ids=self.unique_ids) - def _arrange_arrays(heads, tails, weights, ids=None): """