Skip to content

Commit

Permalink
set_self_weights
Browse files Browse the repository at this point in the history
  • Loading branch information
martinfleis committed Dec 22, 2023
1 parent d528d67 commit b1df00c
Showing 1 changed file with 7 additions and 14 deletions.
21 changes: 7 additions & 14 deletions libpysal/graph/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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):
"""
Expand Down

0 comments on commit b1df00c

Please sign in to comment.