- 博客(90)
- 收藏
- 关注
原创 终端安装多版本python,Anaconda
主要参考文献:http://www.tuicool.com/articles/MBNrquE, http://www.cnblogs.com/micrari/p/5693652.html1.安装pyenv,使用 de >homebrewde> brew install pyenv2.查看pyenv可以安装的版本列表$ pyenv install --list3.安装指定的py
2016-07-23 18:17:50 425
原创 Format for statistical report
1.Introduction- background(where dataset come from? sample size? what variable? variable description) assume:读者对数据不了解- objectives- literature review (what models/methods are available for such data
2016-07-23 18:17:45 216
原创 添加新元素
append()总是把新的元素添加到 list 的尾部。用list的 insert()方法,它接受两个参数,第一个参数是索引号,第二个参数是待添加的新元素L.insert(0, 'Paul') 的意思是,'Paul'将被添加到索引为 0 的位置上(也就是第一个),而原来索引为 0 的Adam同学,以及后面的所有同学,都自动向后移动一位。#假设新来一名学生Paul,Paul 同学的成绩比Bart好,
2016-07-23 18:17:29 269
原创 倒序访问list
L[-4] 报错了,因为倒数第四不存在,一共只有3个元素。使用倒序索引时,也要注意不要越界。#三名同学的成绩可以用一个list表示:L = [95.5, 85, 59]请按照倒序索引分别打印出倒数第一、倒数第二、倒数第三、倒数第四的分数。L = [95.5, 85, 59]print L[-1]print L[-2]print L[-3]print L[-4]
2016-07-23 18:17:24 358
原创 按照索引访问list
#需要特别注意的是,索引从 0 开始,也就是说,第一个元素的索引是0,第二个元素的索引是1,以此类推。报错了!IndexError意思就是索引超出了范围,因为上面的list只有3个元素,有效的索引是 0,1,2。所以,使用索引时,千万注意不要越界。L = [95.5,85,59]print L[0]print L[1]print L[2]print L[2]
2016-07-23 18:17:19 295
原创 创建list
#假设班里有3名同学:Adam,Lisa和Bart,他们的成绩分别是 95.5,85 和 59,请按照 名字, 分数, 名字, 分数... 的顺序按照分数从高到低用一个list表示,然后打印出来。 L = ['Adam', 95.5, 'Lisa', 85, 'Bart', 59]print L
2016-07-23 18:17:14 361
原创 转:布尔类型(短路计算)
在Python中,布尔类型还可以与其他数据类型做 and、or和not运算,请看下面的代码:a = Trueprint a and 'a=T' or 'a=F'计算结果不是布尔类型,而是字符串 'a=T',这是为什么呢?因为Python把0、空字符串''和None看成 False,其他数值和非空字符串都看成 True,所以:True and 'a=T' 计算结果是 'a=T'继续计算 'a=T
2016-07-23 18:17:10 351
原创 unicode字符串
# -*- coding: utf-8 -*-目的是告诉Python解释器,用UTF-8编码读取源代码。然后用Notepad++ 另存为... 并选择UTF-8格式保存。#用多行Unicode字符串表示下面的唐诗并打印:#静夜思#床前明月光,#疑是地上霜。#举头望明月,#低头思故乡。print u'''静夜思床前明月光,疑是地上霜。举头望明月,低头思故乡。'''
2016-07-23 18:17:04 315
原创 raw字符串与多行字符串
#请把下面的字符串用r'''...'''的形式改写,并用print打印出来:#'\"To be, or not to be\": that is the question.\nWhether it\'s nobler in the mind to suffer.'print r'''"To be, or not to be": that is the question.Whether it's n
2016-07-23 18:16:59 269
原创 定义字符串
#请将下面两行内容用Python的字符串表示并打印出来:#Python was started in 1989 by "Guido".#Python is free and easy to learn.s = 'Python was started in 1989 by "Guido".\nPython is free and easy to learn.'print s
2016-07-23 18:16:54 388
原创 什么是变量
#等差数列可以定义为每一项与它的前一项的差等于一个常数,可以用变量 x1 表示等差数列的第一项,用 d 表示公差,请计算数列1 4 7 10 13 16 19 ...前 100 项的和。x1 = 1d = 3n = 100x100 = x1+(100-1)*3s = 100*x1+n*(n-1)*d/2print s
2016-07-23 18:16:49 258
原创 print 语句
#请用两种方式打印出 hello, python.print 'hello, python'print 'hello,','python'
2016-07-23 18:16:44 276
原创 二,八,十,十六进制输入转换
Python中:2进制是以0b开头的: 例如: 0b11 则表示十进制的38进制是以0开头的: 例如: 011则表示十进制的9 16进制是以0x开头的: 例如: 0x11则表示十进制的17转换为2进制 bin()转换为8进制 oct()转换为10进制 int()转换为16进制hex()---------------------------------------------------------
2016-07-23 18:16:39 310
原创 数据类型
#计算十进制整数 45678 和十六进制整数 0x12fd2 之和print 45678+0x12fd2#请用字符串表示出Learn Python in imoocprint 'Learn Python in imooc'#请计算以下表达式的布尔值(注意==表示判断是否相等):#100 #0xff == 255print 100 print 0xff == 255
2016-07-23 18:16:33 307
原创 *while计算用户输入的数字的总和
# whilesum.pyn = input('How many numbers to sum ?')total = 0i = 1while i n: s = raw_input('enter' + ' number' + str(i + 1) + ':') total = total + int(s) i = i + 1print('The sum is '+ str(tota
2016-07-23 18:16:28 821
原创 *for计算用户输入的数字的总和
#forsum.pyn = input('How many numbers to sum?')total = 0for i in range(n): s = raw_input('Enter number' + str(i + 1) + ':') total = total + int(s)print('The sum is ' + str(total))
2016-07-23 18:16:23 652
原创 *for计算阶乘
# forfact.pyn = input('Enter an integer >= 0 :')fact = 1for i in range(2,n+1): fact = fact * iprint(str(n) + ' factorial is ' + str(fact))
2016-07-23 18:16:16 361
原创 *while计算阶乘
# whilefact.pyn = input('Enter an integer >= 0:')fact = 1i = 2while i n: fact = fact * i i = i + 1print(str(n)+'factorial is' + str(fact))
2016-07-23 18:16:12 7484 1
原创 range函数
for i in range(0,10,1): print(i)momodeMacBook-Air:python momo$ python haha.py0123456789for i in range(10,0,-1): print(i)momodeMacBook-Air:python momo$ python haha.py10987654321注意:rang
2016-07-23 18:16:06 2175
原创 elif语句
#airfare.pyage = input('How old are you?')if age 2: print('free')elif 2age 13: print('child fare')else: print('adult fare')
2016-07-23 18:16:04 622
原创 Merry Christmas Eve
#password1.pypwd = raw_input('what is the password?')if pwd =='apple': print('Merry Christmas Eve!')else: print("You're a idiot!")print('Haha!')
2016-07-23 18:16:01 366
原创 input函数在py2和py3的区别
在python2中从控制台接收输入的方式有两种:input()和raw_input(),当输入为纯数字时input返回的是数值类型,如int,floatraw_inpout返回的是字符串类型,string类型输入字符串为表达式input会计算在字符串中的数字表达式,而raw_input不会。如输入 “57 + 3”,input会得到整数60,而raw_input会得到字符串”57 + 3”在pyt
2016-07-23 18:15:58 437
原创 THE LION KING
Today I wanna talk about a familiar classic movie. The reason why I want to introduce it is that it’s my first time to buy a ticket into the cinema to see a movie, so I have a deep impression of this.
2016-07-23 18:15:55 264
原创 导入模块,以模块math为例
方法1>>> import math>>> math.cos(1)0.5403023058681398方法2>>> from math import*运行后,调用函数不用再加math前缀,但如果函数与math模块中某个函数同名,将被math模块中的同名函数覆盖,不建议用这种方式>>> from math import sin,tan可以导入模块中的特定函数
2016-07-23 18:15:53 6131
原创 文本分词,记词频,做词云
a b ?table lecture=read.csv("1.segment.txt",sep=",",header=TRUE,fileEncoding="UTF-8") # 查看前几行,看是否有字符编码问题 head(lecture); # 获取数据集长度 n=length(lecture[,1]); print(n) # == 文本预处理 res=lecture[lecture
2016-07-23 18:15:45 1010
原创 while
// 一个计数循环#include int main(void){ const int NUMBER = 22; int count = 1; //初始化 while ( count //判断 { printf("Be my valentine!\n"); //动作 count=c
2016-07-23 18:15:42 433
原创 递归
#include int factorial(int n){ /* base case */ if (n == 0) return 1; else{ int recurse = factorial(n-1); int result = n*recurse; return result;
2016-07-23 18:15:39 237
原创 ?? if/else 布尔 return
#include int as_leap(int x){ if (x % 400 == 0) return 1; else return 0;/* 一定要写else return 0 ? */}int i = 1600;int main(void){ if (as_leap(i)) { pr
2016-07-23 18:15:34 232
原创 return语句
/* 知识点:1.异或逻辑表达式; 2.return返回值的理解:函数返回一个值相 当于定义一个和返回值类型相同的临时变量并用return后面的表达式来初始化。3.c语言的传参规则是”call by value“,即按值传递,返回值也是按值传递的,即便返回语句写成return x;,返回的也是变理x的值,而非变量x本
2016-07-23 18:15:31 299
原创 逻辑运算符
& | !分别是逻辑运算符与、或、非(条件1)&&(条件2) 条件1和条件2都成立,则表达式为真,否则为假(条件1)||(条件2) 条件1和条件2有一个成立,则表达式为真,只有两个条件都为假时,表达 式才为假 !(条件) 可以理解为求反,条件为真,表达式为假;条件为假,表达式为真
2016-07-23 18:15:27 253
原创 switch语句
#include void print_day(int day){ switch (day) { case 1: case 2: case 3:printf("haha\n"); case 4: case 5: printf("weekday\n"); bre
2016-07-23 18:15:19 152
原创 使用数学函数
#include #include int main(void){ double pi =3.1416; printf("sin(pi/2)=%f\nln1=%f\n",sin(pi/2),log(1.0)); return 0;}momodeMacBook-Air:c momo$ gcc try.cmomodeMacBook-Air:c momo$ ./a.ou
2016-07-23 18:15:12 206
原创 基础补缺:rep,dim,length
#加括号是可以直接让赋值语句计算出结果(a#rep中有each和无each的区别rep(a,each=2)> rep(a,each=2) [1] 0 0 5 5 10 10 15 15 20 20 25[12] 25 30 30 35 35 40 40 45 45 50 50[23] 55 55 60 60 65 65 70 70
2016-07-23 18:15:09 549
原创 自相关函数acf pacf
income "income_end.txt",header = T)y 7]x 1]acf(y,na.action = na.pass) #缺失值出现?acfpacf(y,na.action = na.pass)
2016-07-23 18:15:03 10662
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人