
python
iduanbin
Stay hungry. Stay foolish
展开
-
python基本变量和函数基础
一起学习,未完待续。。。原创 2017-01-12 21:07:27 · 206 阅读 · 0 评论 -
python getA() 函数
此函数将矩阵类型转化为数组,与mat函数正好相反;>>> a = [[1,2,3], [3,4,5]]>>> matb = mat(a)>>> matbmatrix([[1, 2, 3], [3, 4, 5]])>>&原创 2019-03-13 17:56:31 · 7080 阅读 · 0 评论 -
python [example[i] for example in dataSet] 列表for循环
featList = [example[i] for example in dataSet]classList = [example[-1] for example in dataSet]将dataSet中的数据先按行依次放入example中,然后取得example中的example[i]元素,放入列表featList中>>> dataSet[[1, 1, 'yes'],...原创 2019-03-08 16:22:17 · 2064 阅读 · 0 评论 -
python 生产者消费者模型
第一种:from Queue import Queueimport random,threading,time#生产者类class Producer(threading.Thread): def __init__(self, name,queue): threading.Thread.__init__(self, name=name) self.d...原创 2019-03-08 16:18:11 · 165 阅读 · 0 评论 -
python 调用shell的方式
【1】os.system( shell_command )直接在终端输出执行结果,返回执行状态0或者1此函数会启动子进程,在子进程中执行command,并返回command命令执行完毕后的退出状态,如果command有执行内容,会在标准输出显示。这实际上是使用C标准库函数system()实现的;缺点:这个函数在执行command命令时需要重新打开一个终端,并且无法保存command命令的执行...原创 2019-03-08 16:15:37 · 772 阅读 · 0 评论 -
pyhton dict 中的 items() 和 iteritems() 函数
1.字典的items方法作用:是可以将字典中的所有项,以列表方式返回。因为字典是无序的,所以用items方法返回字典的所有项,也是没有顺序的。2.字典的iteritems方法作用:与items方法相比作用大致相同,只是它的返回值不是列表,而是一个迭代器。它们的类型不一样。>>> x = {"name": "jack", "age": 18}>>> b = ..原创 2019-03-02 11:44:13 · 352 阅读 · 0 评论 -
python operator.itemgetter() 函数
operator模块提供的itemgetter函数用于获取对象的哪些维的数据,参数为一些序号。看下面的例子a = [1,2,3] >>> b=operator.itemgetter(1) # 定义函数b,获取对象的第1个域的值>>> b(a) 2...原创 2019-03-02 11:43:16 · 153 阅读 · 0 评论 -
python list中的 sort()函数 和 sorted()函数
list.sort(cmp=None, key=None, reverse=False)1.cmp – 可选参数, 如果指定了该参数会使用该参数的方法进行排序。2.key – 主要是用来进行比较的元素,只有一个参数,具体的函数的参数就是取自于可迭代对象中,指定可迭代对象中的一个元素来进行排序。3.reverse – 排序规则,reverse = True 降序, reverse = Fal...原创 2019-03-02 11:41:52 · 182 阅读 · 0 评论 -
python numpy中的 argsort
将元素从小到大排列,然后提取索引;axis = 0 按行排序axis = 1 按列排序例如:原始数据3,0,2,1,4,5排序之后0,1,2,3,4,5排序之后的在原始数据中的索引,如:0在原始数据中索引是11,3,2,0,4,5>>> a = array([2, 3, 1])>>> argsort(a) # 升序排列array...原创 2019-03-02 11:35:44 · 174 阅读 · 0 评论 -
python中 sum() 函数
sum( axis = 0 ),列的相加;sum( axis = 1 ),行的相加;sum(),总的相加;>>> c = array([[1,2, 1], [2, 1, 0], [3,2,1]])>>> carray([[1, 2, 1], [2, 1, 0], [3, 2, 1]]) >>&...原创 2019-03-02 11:32:20 · 4259 阅读 · 0 评论 -
python numpyshape() 函数
>>> from numpy from *>>> a = array( [ [1,2,3], [2,3,4] ] )>>> a.shape(2,3)>>> a.shape[0] # 行数2>>> a.shape[1] #列数3原创 2019-03-02 11:30:05 · 337 阅读 · 0 评论 -
python numpy 中 tile() 函数
tile( A, B )将A重复B次,B可以是int类型也可以是元组;>> tile( [0, 1], 1] ) # B为int类型array([0,1]])>> tile( [0, 1], 2 )array([0, 1, 0, 1])>> tile( [0, 1], (2, 1) ) # B为元组类型array( [0, 1]原创 2019-03-02 11:18:49 · 220 阅读 · 0 评论 -
用python绘制出主机内存折线图-直观的观察主机内存情况
写的比较粗糙,可以作为一种思路参考;点开脚本能生成内存变化的折线图(python绘制更多图形请参考matplotlib): [1] 先获取主机内存情况,用shell:readMem.sh :memFilename="memory.txt"ubantu(){ while true do mem=`df -a | grep "^/dev" | awk '{print原创 2017-11-09 11:01:14 · 1330 阅读 · 0 评论