laiterry / blogs Goto Github PK
View Code? Open in Web Editor NEWprogramming notebook
License: MIT License
programming notebook
License: MIT License
csv最后一行是空行
python内置CSV读出来的是string,可以使用pandas, 将数据读成float
散点图的坐标有问题,原因是数据是string而不是数字
the last line of csv is an empty line
use pandas to read csv instead of built-in csv function
the csv built-in function read the float number as a string, when we plot scatter plot, the data is string, therefore the number on the axis will have a wrong order
dataframe转化成array
df=df.values
array转化成dataframe
import pandas as pd
df = pd.DataFrame(df)
df = pd.read_csv(filename,header=None)
df = df.values
取前三列
a_array =df[:,0:3]
取第四列
b_vector = df[:,4]
函数参数输入
1.graph
单向图,只有一个可用方法,参数:node, 返回:该node的相邻节点
2.source
3.destination
作用:
1.每次加入、删除、pop操作一个值,heapq都会重新将堆中的数值从新排序,最小的在前面
2.heapq中的数值可以是数字,也可以是元组,例如(5,'abc'), 或 (5, ('abc', 'a'))
用到的方法:
1.heapq.heappush
2.heapq.heappop
1.将起点heapq.heappush到堆中
2.当堆不为空时, 当前node = pop堆,将node加入已探索的列表,对node的每一个可到达的相邻节点next_node,计算到达该相邻节点next_node的距离 distance = 到达node的最短距离 + edge 的长度,然后将node和距离作为元组push到堆中。虽然distance不一定是到达相邻节点next_node的最小距离,但是由于我们将每一个可能到达next_node的距离都会push到堆中,当我们第一次探索该点的时候,虽然没有穷尽到达该点的方法,但是访问该点的最小路径一定以及存在与堆中了,因为堆中包含了起点到目前已探索范围边缘点的路径长度。而pop堆选出来的则是下一个可到达所有边缘点的路径最小的一个。
3.当我们探索到下一个点next_node的时候,到达next_node的相邻的节点next_next_node的最小路径就会多了一个可能的值,我们也把它push到堆中
4.堆中可能存在多个到达某点的最短路径,我们只取最小的那次,当某点被pop多于1次,我们可以发现多出来的这几次就是到达改点的其他路径,我们用continue忽略掉就可以
5.当我们pop到目标点的时候,说明我们已经找到最短路径了
1.list数组append一个新的值的时候,append(a,b) 是错的,应该append((a,b)),因为append只接受一个参数
2.列表推导式书写形式:
[表达式 for 变量 in 列表] 或者 [表达式 for 变量 in 列表 if 条件]
References:
1.https://campus.datacamp.com/courses/network-analysis-in-python-part-1/important-nodes?ex=8
2.http://btechsmartclass.com/DS/U3_T8.html
3.http://www.bogotobogo.com/python/python_Dijkstras_Shortest_Path_Algorithm.php
4.https://campus.datacamp.com/courses/network-analysis-in-python-part-1/important-nodes?ex=8
[表达式 for 变量 in 列表]
或者 [表达式 for 变量 in 列表 if 条件]
fruits = ['banana', 'apple', 'mango']
for index in range(len(fruits)):
print '当前水果 :', fruits[index]
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.