MCPcopy Create free account
hub / github.com/easy-graph/Easy-Graph / degree

Method degree

easygraph/classes/graph.py:377–423  ·  view source on GitHub ↗

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")

Source from the content-addressed store, hash-verified

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.

Callers 15

sizeMethod · 0.95
graph_to_d_atleast2Function · 0.95
is_isolateFunction · 0.45
isolatesFunction · 0.45
forwardMethod · 0.45
NOBE_GAFunction · 0.45
k_coreFunction · 0.45
draw_SHS_centerFunction · 0.45
draw_SHS_center_kkFunction · 0.45
draw_kamada_kawaiFunction · 0.45
plot_FollowersFunction · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected