Returns the weighted degree of of each node. Parameters ---------- weight : string, optional (default: 'weight') Weight key of the original weighted graph. Returns ------- degree : dict Each node's (key) weighted degree (value
(self, weight="weight")
| 375 | self.graph["name"] = s |
| 376 | |
| 377 | def degree(self, weight="weight"): |
| 378 | """Returns the weighted degree of of each node. |
| 379 | |
| 380 | Parameters |
| 381 | ---------- |
| 382 | weight : string, optional (default: 'weight') |
| 383 | Weight key of the original weighted graph. |
| 384 | |
| 385 | Returns |
| 386 | ------- |
| 387 | degree : dict |
| 388 | Each node's (key) weighted degree (value). |
| 389 | |
| 390 | Notes |
| 391 | ----- |
| 392 | If the graph is not weighted, all the weights will be regarded as 1. |
| 393 | |
| 394 | Examples |
| 395 | -------- |
| 396 | You can call with no attributes, if 'weight' is the weight key: |
| 397 | |
| 398 | >>> G.degree() |
| 399 | |
| 400 | if you have customized weight key 'weight_1'. |
| 401 | |
| 402 | >>> G.degree(weight='weight_1') |
| 403 | |
| 404 | """ |
| 405 | if self.cache.get("degree") != None: |
| 406 | return self.cache["degree"] |
| 407 | degree = dict() |
| 408 | for u, v, d in self.edges: |
| 409 | if u in degree: |
| 410 | degree[u] += d.get(weight, 1) |
| 411 | else: |
| 412 | degree[u] = d.get(weight, 1) |
| 413 | if v in degree: |
| 414 | degree[v] += d.get(weight, 1) |
| 415 | else: |
| 416 | degree[v] = d.get(weight, 1) |
| 417 | |
| 418 | # For isolated nodes |
| 419 | for node in self.nodes: |
| 420 | if node not in degree: |
| 421 | degree[node] = 0 |
| 422 | self.cache["degree"] = degree |
| 423 | return degree |
| 424 | |
| 425 | def order(self): |
| 426 | """Returns the number of nodes in the graph. |
no outgoing calls
no test coverage detected