一波儿networkx 读写edgelist,给节点加attribute的操作

一波儿networkx 读写edgelist,给节点加attribute的操作 read more: nx official: Reading and writing graphs import numpy as np import networkx as nx import operator G1 = nx.DiGraph(name='network1') # Directed Graph #networkx 导入edgelist with open(net1_path, 'r') as edgeReader: # 从文件中读取edgelist生成Graph of networkx for line in edgeReader.readlines(): edges_net1.append(tuple(map(int, line.strip().split(' ')))) G1.add_edges_from(edges_net1) print('\n== info of net1 original: ') print(nx.info(G1)) triad_list_net1 = [] for i in edges_net1: triad = tuple([i[0], i[1], i[0]+i[1]]) triad_list_net1.append(triad) # list of triads triad_list_net1.sort(key=operator.itemgetter(2)) # sort the list by the 3rd item of triad isgt_dict1 = dict(zip(G1.

READ MORE

The list of list is modified unexpected, python

Be careful! The list of list is modified unexpected, python # code patch A: list = [1,2,3,4,5,6,7] print('list A :', list) for i in list: temp = i if i > 5: temp = i + 10000 print('list A\':', list) # code patch B: list = [[1],[2],[3],[4],[5],[6],[7]] new_list = [] print('\nlist B : ',list) for i in list: temp = i # will this allocate a new RAM space for var 'temp'? if i[0] > 5: temp[0] = i[0] + 1000 new_list.

READ MORE

Graph Convolutional Network

How to do Deep Learning on Graphs with Graph Convolutional Networks https://towardsdatascience.com/how-to-do-deep-learning-on-graphs-with-graph-convolutional-networks-7d2250723780 scientific internet may need.

READ MORE

Check the port occupy on Mac OSX

Check the port occupy on Mac OSX lsof -i :7070 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME sivoxy 64888 wgg 6u IPv4 0x6ddd270 0t0 TCP *:gds_db (LISTEN) We have the PID of that app occupying port. Locating the executable file of that PID ps xuwww -p PID PID (64888) is the process id you are looking. for More help on pscommand you can find with man ps

READ MORE

Change the environment variable for python code running

python程序运行中改变环境变量: Trying to change the way the loader works for a running Python is very tricky; probably OS/version dependent; may not work. One work-around that might help in some circumstances is to launch a sub-process that changes the environment parameter using a shell script and then launch a new Python using the shell. So, before the python code is executed, the env var is loaded. Ref: https://stackoverflow.com/questions/1178094/change-current-process-environments-ld-library-path But how to launch a sub-process that changes the environment parameter: You can ref: https://stackoverflow.

READ MORE

basic deepwalk

Get to know How deepwalk works by this project. Two steps: 1. gen the graph, and gen the corpus on the graph via random walk. 2. use the corpus generated by step1 to fit the Word2vec model and calculate the similarity of two nodes. Project link: https://gitee.com/sonica/basic-deepwalk Read more about develop word2vec model with python: https://machinelearningmastery.com/develop-word-embeddings-python-gensim/ This blog will tell you: How to train your own word2vec word embedding model on text data. How to visualize a trained word embedding model using Principal Component Analysis.

READ MORE

kwargs - Key words arguments in python function

This is a tutorial of how to use *args and **kwargs For defining the default value of arguments that is not assigned in key words when calling the function: def func(**keywargs): if 'my_word' not in keywargs: word = 'default_msg' print(word) else: word = keywargs['my_word'] print(word) call this by: func() func(my_word='love') you’ll get: default_msg love read more about *args and **kwargs in python: https://www.digitalocean.com/community/tutorials/how-to-use-args-and-kwargs-in-python-3 Add more about default value if arg key is not assigned: def make_hastie_10_2(n_samples=12000, random_state=None): """Generates data for binary classification used in Hastie et al.

READ MORE

Graph Neural Networks for Computer Vision

Graph Neural Networks for Computer Vision I was attracted by this image: This is an inspiring image and it was posted in this article: Tutorial on Graph Neural Networks for Computer Vision and Beyond (Part 1) written by Boris, a PhD student at University of Guelph. Link: https://medium.com/@BorisAKnyazev/tutorial-on-graph-neural-networks-for-computer-vision-and-beyond-part-1-3d9fada3b80d The figure I attached above is showing some possibilities that using the graph structure to represent the version components in a fuzzy way. That’s innovative and interesting.

READ MORE

Convert Adjacency matrix into edgelist

Table of Contents [Edge List <– Adjacency Matrix](# Edge List <– Adjacency Matrix) [Edge List –> Adjacency Matrix](# Edge List –> Adjacency Matrix) [About Adjacency List](#About Adjacency List) Edge List <– Adjacency Matrix ''' ref: https://www.cnblogs.com/sonictl/p/10688533.html convert adjMatrix into edgelist: 'data/unweighted_edgelist.number' or 'data/weighted_edgelist.number'' input: adjacency matrix with delimiter=', ' it can process: - Unweighted directed graph - Weighted directed graph output: edgelist (unweighted and weighted) ''' import numpy as np import networkx as nx # -------DIRECTED Graph, Unweighted----------- # Unweighted directed graph: a = np.

READ MORE

Mac 日常使用tips

29190923: 【Mac快捷键】光标及 delete 删除光标右侧文字 Ctrl + a = home Ctrl + e = end Ctrl + p = 上 Ctrl + n = 下 Ctrl + b = 左 Ctrl + f = 右 Ctrl + d = delete 删除光标右侧文字 20180725: windows标准的键盘连接了mac如何映射键盘?最大的好处是可以向后删除,还可以一键PageUP, PageDown ref: https://support.apple.com/zh-cn/HT202676 Win-> Command Alt -> Alt Ctrl-> control Mission Control: Ctrl+↑, Ctrl+←, Ctrl+→ LaunchPad: Win+F10, Or: Fn + Win + F10 in case the FnLk is not activated. Home and End disabled sometimes.

READ MORE