Returns the number of edges or total of all edge weights. Parameters ----------- weight : String or None, optional The weight key. If None, it will calculate the number of edges, instead of total of all edge weights. Returns -------
(self, weight=None)
| 444 | return len(self._node) |
| 445 | |
| 446 | def size(self, weight=None): |
| 447 | """Returns the number of edges or total of all edge weights. |
| 448 | |
| 449 | Parameters |
| 450 | ----------- |
| 451 | weight : String or None, optional |
| 452 | The weight key. If None, it will calculate the number of |
| 453 | edges, instead of total of all edge weights. |
| 454 | |
| 455 | Returns |
| 456 | ------- |
| 457 | size : int or float, optional (default: None) |
| 458 | The number of edges or total of all edge weights. |
| 459 | |
| 460 | Examples |
| 461 | -------- |
| 462 | |
| 463 | Returns the number of edges in G: |
| 464 | |
| 465 | >>> G.size() |
| 466 | |
| 467 | Returns the total of all edge weights in G: |
| 468 | |
| 469 | >>> G.size(weight='weight') |
| 470 | |
| 471 | """ |
| 472 | if self.cache.get("size") != None: |
| 473 | return self.cache["size"] |
| 474 | s = sum(d for v, d in self.degree(weight=weight).items()) |
| 475 | self.cache["size"] = s // 2 if weight is None else s / 2 |
| 476 | return self.cache["size"] |
| 477 | |
| 478 | # GCN Laplacian smoothing |
| 479 | @property |
no test coverage detected