Returns the weighted in degree of each node. Parameters ---------- weight : string, optional (default : 'weight') Weight key of the original weighted graph. Returns ------- in_degree : dict Each node's (key) weighted in degree
(self, weight="weight")
| 170 | return degree |
| 171 | |
| 172 | def in_degree(self, weight="weight"): |
| 173 | """Returns the weighted in degree of each node. |
| 174 | |
| 175 | Parameters |
| 176 | ---------- |
| 177 | weight : string, optional (default : 'weight') |
| 178 | Weight key of the original weighted graph. |
| 179 | |
| 180 | Returns |
| 181 | ------- |
| 182 | in_degree : dict |
| 183 | Each node's (key) weighted in degree (value). |
| 184 | |
| 185 | Notes |
| 186 | ----- |
| 187 | If the graph is not weighted, all the weights will be regarded as 1. |
| 188 | |
| 189 | See Also |
| 190 | -------- |
| 191 | out_degree |
| 192 | degree |
| 193 | |
| 194 | Examples |
| 195 | -------- |
| 196 | |
| 197 | >>> G.in_degree(weight='weight') |
| 198 | |
| 199 | """ |
| 200 | degree = dict() |
| 201 | for u, v, d in self.edges: |
| 202 | if v in degree: |
| 203 | degree[v] += d.get(weight, 1) |
| 204 | else: |
| 205 | degree[v] = d.get(weight, 1) |
| 206 | |
| 207 | # For isolated nodes |
| 208 | for node in self.nodes: |
| 209 | if node not in degree: |
| 210 | degree[node] = 0 |
| 211 | |
| 212 | return degree |
| 213 | |
| 214 | def degree(self, weight="weight"): |
| 215 | """Returns the weighted degree of each node, i.e. sum of out/in degree. |
no outgoing calls
no test coverage detected