
python
文章平均质量分 53
Yuli_Derek
我不去想是否能够成功 既然选择了远方 便只顾风雨兼程 我不去想能否赢得爱情 既然钟情于玫瑰 就勇敢地吐露真诚 我不去想身后会不会袭来寒风冷雨 既然目标是地平线 留给世界的只能是背影 我不去想未来是平坦还是泥泞 只要热爱生命 一切都在意料之中
展开
-
json.load() vs json.loads()
json.load:Deserialize fp (a .read()-supporting file-like object containing a JSON document) to a Python object using this conversion table.json.loads:Deserialize s (a str or unicode instance原创 2013-05-07 13:13:30 · 4206 阅读 · 0 评论 -
【Python排序搜索基本算法】之Dijkstra最短路径算法(Dijkstra's Shortest-Path Algorithm)
Single-Source shortest PathsInput directed graph G = (V,E) (m = |E|, n = |V|) ---each edge has nonnegative length ---source vertex soutput: for each v, compute L(v) = length of a sho原创 2013-08-13 20:57:15 · 3722 阅读 · 0 评论 -
【Python基础】之对字典进行排序操作(sort by the values of dict)
import operatorresult = sorted(dict.iteritems(), key = operator.itemgetter(1))The type of result is "list" and is sorted by the values of dict in ascending order.原创 2013-05-08 20:02:13 · 1356 阅读 · 0 评论 -
【Python排序搜索基本算法】之深度优先搜索、广度优先搜索、拓扑排序、强联通&Kosaraju算法
Graph Search and Connectivity Generic Graph Search Goals 1. find everything findable 2. don't explore anything twice Generic Algorithm (given graph G, vertex S)原创 2013-08-09 15:47:17 · 2615 阅读 · 0 评论 -
【Python基础】之copy and deepcopy
在Python中,无论你把对象做为参数传递,做为函数返回值,都是引用传递的。标准库中的copy模块提供了两个方法来实现拷贝.一个方法是copy(shallow copy),它返回和参数包含内容一样的对象。浅拷贝是指拷贝的只是原对象元素的引用,换句话说,浅拷贝产生的对象本身是新的,但是它的内容不是新的,只是对原对象的一个引用。这里有个例子>>> a=[[1, 2], 3, 4原创 2013-08-02 18:10:11 · 1548 阅读 · 0 评论 -
【Python排序搜索基本算法】之归并排序&分治法(Merge Sort and Divide & Conquer)
Merge Sort is a good introduction to divide & conquer.The Big O of Merge Sort Algorithm is O(nlog(n)).The divide & conquer Paradigm1. Divide into small subproblems2. Conquer via recursive原创 2013-07-14 21:50:36 · 1576 阅读 · 0 评论 -
【Python基础】之has_key(key) or key in d
如果不知道dict中是否有key的值,那么最好用dict.get(key)如果用dict[key]这个读取会报KeyError异常d = {'a': 1, 'b': 2}'a' in dTrueor:d = {'a': 1, 'b': 2}d.has_key('a')TrueIn fact has_key() was removed in Pytho转载 2013-05-07 15:09:16 · 1429 阅读 · 0 评论 -
【Python基础】之set, list, dictionary
1. Simple expression3e-10 #10的-10次10//3 #10/3的整数部分10%3 #余数2.Setsx = {} #dictionary not setx = set() #setsum({1,2,3})sum({1,2,3}, 3)num = {1,2,3}2 in num #return True2 not原创 2013-07-16 15:50:59 · 1203 阅读 · 0 评论 -
【Python排序搜索基本算法】之快速排序(QuickSort)
def choosePivot(number, l, r): #choose the first element as the Pivot p = l return pdef partition(number, l, r, p): number[l], number[p] = number[p], number[l] #swap the lth number a原创 2013-07-22 22:11:27 · 1654 阅读 · 0 评论 -
【Python排序搜索基本算法】之无向图的最小割&Karger算法(Graphs and Minimum Cuts & Karger's Min-Cut Algorithm)
Graphs Two ingredients 1. vertices (nodes) v 2. edges(undirected or directed)Examples: road networks, the web, social networksThe minimum Cut problem Input: undirected g原创 2013-08-02 19:37:52 · 4831 阅读 · 2 评论 -
【Python基础】之全局变量(UnboundLocalError: local variable referenced before assignment)
count = 0def function(): count = count + 1 print(count)Then we get: UnboundLocalError: local variable 'count' referenced before assignmentThe reason this happens is because as so原创 2013-07-14 22:07:32 · 29973 阅读 · 0 评论 -
python,numpy等的安装方式以及Theano的安装、vim的python开发环境配置总结
首先讲一下写这篇文章的动机,之前已经写过一段时间的python代码了,但是基本上仅限于基本的算法和机器学习方面的算法,对Linux、Mac OS下的环境也不是很熟悉。 不过最近开始研究Deep Learning,准备捣鼓下Montreal 大学Yoshua Bengio等人搞的python的包Theano(论文地址:http://www.iro.umontreal.ca/~lisa/po原创 2013-12-29 16:26:24 · 4797 阅读 · 2 评论