锘??xml version="1.0" encoding="utf-8" standalone="yes"?>伊人色综合久久天天,99精品久久久久久久婷婷,国产精品美女久久福利网站http://www.shnenglu.com/luyulaile/category/19897.htmlI canzh-cnTue, 04 Dec 2012 08:21:22 GMTTue, 04 Dec 2012 08:21:22 GMT60Python extract all comments:鎻愬彇鎵鏈塩omments,鎻愬彇c/c++涓敞閲奝ython鑴氭湰http://www.shnenglu.com/luyulaile/archive/2012/12/03/195907.htmlluisluisMon, 03 Dec 2012 00:35:00 GMThttp://www.shnenglu.com/luyulaile/archive/2012/12/03/195907.htmlhttp://www.shnenglu.com/luyulaile/comments/195907.htmlhttp://www.shnenglu.com/luyulaile/archive/2012/12/03/195907.html#Feedback0http://www.shnenglu.com/luyulaile/comments/commentRss/195907.htmlhttp://www.shnenglu.com/luyulaile/services/trackbacks/195907.html濡傛灉 紼嬪簭涓嚭鐜頒簡“/*”,浼氭湁bug

#!/usr/bin/env python

import sys
import re

def comment_finder(text):
    pattern = re.compile( r'//.*?$|/\*.*?\*/', re.DOTALL | re.MULTILINE)
    result = pattern.findall(text)
    return result

def print_command(filename):

    codefile = open(filename,'r')
    commentfile = open(filename+".txt",'w')
    lines=codefile.read()
    codefile.close()
    #the list of comments
    list_of_comments = comment_finder(lines)
    for comment in list_of_comments:
        #print comment[0:2]
        if comment[0:2] == "//":
                comment_to_write = comment[2:]
        else:
            comment_to_write = comment[2:-2]
        if len(comment_to_write)!=0:
            commentfile.write(comment_to_write)
        commentfile.write('\n')
    commentfile.close()

if __name__ == "__main__":
    for filename in sys.argv[1:]:
        print_command(filename)
浣跨敤錛?br />
鍦╨inux涓嬮潰 杞埌褰撳墠鐩綍 ./get_comment.py *
鎴栬?鎸囧畾鏂囦歡綾誨瀷
./get_comment.py *.c


luis 2012-12-03 08:35 鍙戣〃璇勮
]]>
Python 絎旇 pi tan 絳夊叕寮?/title><link>http://www.shnenglu.com/luyulaile/archive/2012/11/08/194861.html</link><dc:creator>luis</dc:creator><author>luis</author><pubDate>Thu, 08 Nov 2012 00:21:00 GMT</pubDate><guid>http://www.shnenglu.com/luyulaile/archive/2012/11/08/194861.html</guid><wfw:comment>http://www.shnenglu.com/luyulaile/comments/194861.html</wfw:comment><comments>http://www.shnenglu.com/luyulaile/archive/2012/11/08/194861.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/luyulaile/comments/commentRss/194861.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/luyulaile/services/trackbacks/194861.html</trackback:ping><description><![CDATA[<div style="text-align: justify;"><div>import math<br />def mianji(n,s):</div><div>    temp=1/4*n*(s**2)/math.tan(math.pi/n)</div><div>    return temp</div><div>print mianji(5,7)<br />============<br />浣跨敤鏃秏ath.pi math.tan</div></div><img src ="http://www.shnenglu.com/luyulaile/aggbug/194861.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/luyulaile/" target="_blank">luis</a> 2012-11-08 08:21 <a href="http://www.shnenglu.com/luyulaile/archive/2012/11/08/194861.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>Python 絎旇2 //http://www.shnenglu.com/luyulaile/archive/2012/11/08/194858.htmlluisluisWed, 07 Nov 2012 22:43:00 GMThttp://www.shnenglu.com/luyulaile/archive/2012/11/08/194858.htmlhttp://www.shnenglu.com/luyulaile/comments/194858.htmlhttp://www.shnenglu.com/luyulaile/archive/2012/11/08/194858.html#Feedback0http://www.shnenglu.com/luyulaile/comments/commentRss/194858.htmlhttp://www.shnenglu.com/luyulaile/services/trackbacks/194858.html
s1 = "hello,world" 
濡傛灉瑕佸啓鎴愬琛岋紝閭d箞灝辮浣跨敤/ (“榪炶絎?#8221;)鍚э紝濡?nbsp;
s2 = "hello,/ 
world" 
s2涓巗1鏄竴鏍風殑銆傚鏋滀綘鐢?涓弻寮曞彿鐨勮瘽錛屽氨鍙互鐩存帴鍐欎簡錛屽涓嬶細 
s3 = """hello, 
world, 
hahaha."""錛岄偅涔坰3瀹為檯涓婂氨鏄?hello,/nworld,/nhahaha.", 娉ㄦ剰“/n”

s5 = "Let's go"  
s4 = 'Let/'s go' 

鎴戜滑涔熷彲浠ユ妸'''  ''' 浣滀負澶氳娉ㄩ噴

str(object) 鍙互灝嗘墍鏈夎漿鍖栦負瀛楃涓層?br />

pythonjava鎻忚堪
or||閫昏緫鎴?/td>
and&&閫昏緫涓?/td>
not錛?/td>閫昏緫闈?/td>
<錛?gt;錛?lt;=錛?gt;=錛?=錛?=鎴?lt;><錛?gt;錛?lt;=錛?gt;=錛?=錛?=姣旇緝鎿嶄綔
is錛宨s notinstanceof韜喚璁よ瘉
||浣嶆垨
&&浣嶄笌
^^浣嶅紓鎴?/td>
<<錛?gt;><<錛?gt;>縐諱綅
+錛?錛?錛?+錛?錛?錛?鍔犲噺涔橀櫎
%%浣欐暟
~~浣嶅彇琛?/td>


//榪愮畻絎? 
10/3==3
120//10==12
121//10==12
122//10==12
130//10==13
10//3.0==3.0

A new operator, //, is the floor division operator. (Yes, we know it 
looks like C++'s comment symbol.) // always performs floor division no 
matter what the types of its operands are, so 1 // 2 is 0 and 1.0 // 
2.0 is also 0.0. 

not ()


luis 2012-11-08 06:43 鍙戣〃璇勮
]]>
label switchinghttp://www.shnenglu.com/luyulaile/archive/2012/10/31/194109.htmlluisluisTue, 30 Oct 2012 19:36:00 GMThttp://www.shnenglu.com/luyulaile/archive/2012/10/31/194109.htmlhttp://www.shnenglu.com/luyulaile/comments/194109.htmlhttp://www.shnenglu.com/luyulaile/archive/2012/10/31/194109.html#Feedback0http://www.shnenglu.com/luyulaile/comments/commentRss/194109.htmlhttp://www.shnenglu.com/luyulaile/services/trackbacks/194109.html姣斿鏈変袱綆辮嫻鏋滐細 絎竴涓瀛愬唴鏈変袱涓嫻鏋滐紝label 涓篴 鐨勬鐜囦負30%,涓篵鐨勬鐜?0%錛岀浜屼釜綆卞瓙鍐呮湁鍥涗釜鑻規灉錛宭abel涓篵鐨勬鐜?0%,label 涓篴鐨勬鐜?0%.
濡傛灉鎴戜滑姹傛墍鏈夌殑鑻規灉鐨勯噸閲忥紝鍙渶瑕佸皢鎵鏈夌殑綆卞瓙鍐呯殑鑻規灉鍙栧嚭鏉ユ眰閲嶉噺鍗沖埢銆?br />浣嗘槸鎴戜滑鍏堟眰label a鐨勭瀛愯嫻鏋滅殑閲嶉噺錛屽姞涓妉abel b鐨勭瀛愯嫻鏋滅殑閲嶉噺錛屽彲鑳藉嚭鐜頒袱嬈″彇鐨勬槸鍚屼竴涓瀛愶紝榪欏氨鏄痩abel switching闂銆?img src ="http://www.shnenglu.com/luyulaile/aggbug/194109.html" width = "1" height = "1" />

luis 2012-10-31 03:36 鍙戣〃璇勮
]]>
Python generate corpus using Dirichlet distributionhttp://www.shnenglu.com/luyulaile/archive/2012/10/28/193960.htmlluisluisSun, 28 Oct 2012 02:13:00 GMThttp://www.shnenglu.com/luyulaile/archive/2012/10/28/193960.htmlhttp://www.shnenglu.com/luyulaile/comments/193960.htmlhttp://www.shnenglu.com/luyulaile/archive/2012/10/28/193960.html#Feedback0http://www.shnenglu.com/luyulaile/comments/commentRss/193960.htmlhttp://www.shnenglu.com/luyulaile/services/trackbacks/193960.htmlAt first, let's define the sample function:

def sample(dist, num_samples=1):
    """
    Uses the inverse CDF method to return samples drawn from an
    (unnormalized) discrete distribution.

    Arguments:

    dist -- (unnormalized) distribution

    Keyword arguments:

    num_samples -- number of samples to draw
    
"""

    cdf = cumsum(dist)
    r = uniform(size=num_samples) * cdf[-1]

    return cdf.searchsorted(r)
As we can see, the sample function input two parameters, one is dist, which can be an un-normalized distribution, another is the sample we want to draw.

Let's see how to generate corpus for Dirichlet--multinomial unigram language model
def generate_corpus(beta, mean, N):
    """
    Returns a corpus of tokens drawn from a Dirichlet--multinomial
    unigram language model. Each token is an instance of one of V
    unique word types, represented by indices 0, , V - 1.

    Arguments:

    beta -- concentration parameter for the Dirichlet prior
    mean -- V-dimensional mean of the Dirichlet prior
    N -- number of tokens to generate
    
"""

    pass # YOUR CODE GOES HERE
    #print mean
    #print beta 
    #print dot(mean,beta)
    #print dirichlet(mean*beta,size=1)
    temp=sample(dirichlet(beta*array(mean),size=1),N)
    #print temp
    return temp
please keep in mind the dirichlet function is  “from numpy.random.mtrand import dirichlet"
and the parameters it receives are corresponding to beta*array(mean). beta is the concentration factor, and mean is the vector which sum to 1.



another way is to generate corpus is using the property:
P(D'|D,H)= Nv+beta_nv/N+beta
def generate_corpus_collapsed(beta, mean, N):
    """
    Returns a corpus of tokens drawn from a Dirichlet--multinomial
    unigram language model using the 'collapsed' generative process
    (i.e., phi is not explicitly represented). Each token is an
    instance of one of V unique word types.

    Arguments:

    beta -- concentration parameter for the Dirichlet prior
    mean -- V-dimensional mean of the Dirichlet prior
    N -- number of tokens to generate
    
"""

    V = len(mean) # vocabulary size

    corpus = zeros(N, dtype=int) # corpus

    Nv = zeros(V, dtype=int) # counts for each word type

    pass # YOUR CODE GOES HERE
    for n in xrange(N):
        corpus[n]=sample((Nv+beta*array(mean))/(n+beta),1)
        Nv[corpus[n]]+=1;    
    return corpus

Let's see how to generate corpus for Mixture of Dirichlet-multinomial unigram language model 

def generate_corpus(alpha, m, beta, n, D, Nd):
    """
    Returns a grouped corpus drawn from a mixture of
    Dirichlet--multinomial unigram language models.

    Arguments:

    alpha -- concentration parameter for the Dirichlet prior over theta
    m -- T-dimensional mean of the Dirichlet prior over theta
    beta -- concentration parameter for the Dirichlet prior over phis
    n -- V-dimensional mean of the Dirichlet prior over phis
    D -- number of documents to generate
    Nd -- number of tokens to generate per document
    
"""
    corpus = GroupedCorpus()

    pass # YOUR CODE GOES HERE
    #determine the topic the distribution for topic dirichlet(dot(m,alpha),size=1)
    #given the topic, the distribtuion for word dirichlet(dot(n,beta),size=1)
    theta=dirichlet(alpha*array(m),1)
    phis=dirichlet(beta*array(n),len(m))
    for d in range(0,D):
        [t]=sample(theta,1)
        #print groupVcab
        corpus.add(str(d),str(t),[str(x) for x in sample(phis[t,:],Nd)])           
    return corpus
娉ㄦ剰鏄疶涓猼opic (group)錛?span style="font-size: 13px; background-color: #eeeeee; ">  phis=dirichlet(beta*array(n),len(m))  浜х敓浜員涓?dirichlet distribution,鐩稿悓鐨則opic t搴旇鍙栧悓涓涓?dirichlet distribution phis[t,:]

luis 2012-10-28 10:13 鍙戣〃璇勮
]]>
Python 絀烘暟緇?/title><link>http://www.shnenglu.com/luyulaile/archive/2012/09/19/191202.html</link><dc:creator>luis</dc:creator><author>luis</author><pubDate>Wed, 19 Sep 2012 01:47:00 GMT</pubDate><guid>http://www.shnenglu.com/luyulaile/archive/2012/09/19/191202.html</guid><wfw:comment>http://www.shnenglu.com/luyulaile/comments/191202.html</wfw:comment><comments>http://www.shnenglu.com/luyulaile/archive/2012/09/19/191202.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/luyulaile/comments/commentRss/191202.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/luyulaile/services/trackbacks/191202.html</trackback:ping><description><![CDATA[<div>Python array 鐢ㄦ硶   <br />鐩存帴 result=[]</div><div>    for x in range(0,N):</div><div>        temp=beta(b,n)</div><div>        print temp</div><div>        if temp >= n:</div><div>            result.append("Yes")  #鐩存帴append</div><div>        else:</div><div>            result.append("No") #鐩存帴append</div><div>    return result</div><img src ="http://www.shnenglu.com/luyulaile/aggbug/191202.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/luyulaile/" target="_blank">luis</a> 2012-09-19 09:47 <a href="http://www.shnenglu.com/luyulaile/archive/2012/09/19/191202.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>Python絎旇http://www.shnenglu.com/luyulaile/archive/2012/09/09/190021.htmlluisluisSun, 09 Sep 2012 06:47:00 GMThttp://www.shnenglu.com/luyulaile/archive/2012/09/09/190021.htmlhttp://www.shnenglu.com/luyulaile/comments/190021.htmlhttp://www.shnenglu.com/luyulaile/archive/2012/09/09/190021.html#Feedback0http://www.shnenglu.com/luyulaile/comments/commentRss/190021.htmlhttp://www.shnenglu.com/luyulaile/services/trackbacks/190021.htmlTutorial 錛?/span> http://www.tutorialspoint.com/python/python_files_io.htm 

Python IO
杈撳嚭 print
str = raw_input("Enter your input: "); print "Received input is : ", str


Python鍙湁涓夌鍙橀噺綾誨瀷 int, string, float? 
typeof(1.5)
璨屼技涓嶆敮鎸侀殣寮忕被鍨嬭漿鎹?br />print str(2.5)  瀵?br />print 2.5 閿?br />print '2.5' 瀵?br />
python 瀹氫箟鏂規硶鏄?br />def MethodName(para,para2): #娉ㄦ剰榪欓噷鐨勫啋鍙?br />      if 

python娉ㄩ噴
#鍗曡娉ㄩ噴
"""  涓変釜鍙屽紩鍙鋒槸澶氳娉ㄩ噴 """

python 寮曠敤
include math


Python鐨剆tr
str(var)綾誨瀷杞崲
len(var)
var.upper()
var.lower()
var[2] 絎笁涓紙娉ㄦ剰涓嬫爣浠?寮濮嬶級鍏冪礌錛岀被浼間簬list
var[:3] 鍓嶄笁涓厓绱狅紝瀹為檯涓婃寚鐨勬槸0鎴鍒?-1鐨勫厓绱?br />var[2:4]涓嬫爣鏄?鍒?-1鐨勬墍鏈夊厓绱?br />
Python鐨刲ist
exampe=[a,b,c,d,e,f];
len(exampe)
鑷甫sort鏂規硶

Python鐨刣ictionary
key -value瀵瑰簲
value鍙互鏄竴涓猯ist
娉ㄦ剰鏂規嫭鍙穂]閲岄潰鍙兘浣跨敤key
鍖哄垎 del dict['Name']


del dict['Name']; # remove entry with key 'Name' dict.clear();     # remove all entries in dict del dict ;        # delete entire dictionary
鑷甫鐨勬柟娉曪細

1cmp(dict1, dict2)
Compares elements of both dict.
2len(dict)
Gives the total length of the dictionary. This would be equal to the number of items in the dictionary.
3str(dict)
Produces a printable string representation of a dictionary
4type(variable)
Returns the type of the passed variable. If passed variable is dictionary then it would return a dictionary type.




Python綾葷殑瀹氫箟鍜岀被鏂規硶鐨勫畾涔?br />瀹氫箟綾諱笉闇瑕佺敤def class,鐩存帴

class ClassName(object):
姣忎釜綾婚兘鏈?__init__(self,arg):
鏂規硶錛屾敞鎰忔槸 宸﹀彸鍚勪袱涓笅鍒掔嚎錛屾誨叡4鏍逛笅鍒掔嚎
 
綾繪柟娉曢兘闇瑕佸寘鍚玸elf榪欎釜鍙傛暟錛屼絾鏄嬌鐢ㄧ殑鏃跺欎笉闇瑕乻elf,瑙佷笅渚?br />                  
渚嬪
class Adder(object):
def __init__(self):
self.baseNum = 2
def prnt_num(self):
print self.baseNum
def add_to_base(self, arg):
# Your code here
self.baseNum+=arg
print self.baseNum
objectVar = Adder()
objectVar.prnt_num()
# Your code here
objectVar.add_to_base(3)

Python涓殑綾誨彉閲忎笉鑳?self.xxx鏉ュ紩鐢紝浣嗘槸鎴愬憳鍙橀噺鍙互
Class variables are special because they belong to the 
class; the objects created do not get their own copies of the class variable. Class variables are accessed using the class name and dot notation.
ClassName.classVar
Class variables are created outside of__init__ 
渚嬪錛?br />
class Widget(object):
objID = 0
def __init__(self):
Widget.objID += 1
# Your code here
self.myID=Widget.objID

甯哥姱閿欒錛歩ndentation is very important  
python indentation error expected an indented block
榪樻湁涓涓敊璇氨鏄?綾繪柟娉曪紝蹇呴』浣跨敤 self鍙傛暟錛屽嵆浣挎病鏈夊弬鏁幫紒錛?/span>
鍙﹀涓涓父閿欑殑鍦版柟灝辨槸 __init__(self,arg) 涓瀹氭槸鍥涙牴涓嬪垝綰?/span>



涓嶄粎瑕佽寰楃暀dent 榪樿璁板緱 緙╄繘








luis 2012-09-09 14:47 鍙戣〃璇勮
]]>
婷婷久久综合九色综合九七| 91精品国产91久久久久久| 久久久久亚洲AV无码专区网站| 亚洲а∨天堂久久精品| 手机看片久久高清国产日韩| 色99久久久久高潮综合影院| 丁香色欲久久久久久综合网| 欧美激情精品久久久久久| 亚洲综合日韩久久成人AV| 1000部精品久久久久久久久| 久久99精品国产麻豆宅宅| 久久久久综合中文字幕| 亚洲AV无码久久精品狠狠爱浪潮| 日韩精品无码久久一区二区三| 伊人久久综合成人网| 久久久久久亚洲精品不卡 | 久久伊人五月丁香狠狠色| 午夜精品久久影院蜜桃| 久久久精品2019免费观看| 久久99精品久久久久久久不卡| 国产A级毛片久久久精品毛片| 99久久免费只有精品国产| 色欲久久久天天天综合网精品 | 国产精品无码久久综合网| 中文字幕亚洲综合久久| 97久久国产综合精品女不卡| 久久综合色区| 久久精品国产99久久丝袜| 97久久精品人人澡人人爽| 粉嫩小泬无遮挡久久久久久| 亚洲精品无码久久久久久| 奇米影视7777久久精品人人爽| 亚洲国产精品综合久久一线 | 久久久久久伊人高潮影院| 久久国产热这里只有精品| 91亚洲国产成人久久精品网址| 69SEX久久精品国产麻豆| 国产国产成人精品久久| 久久精品国产免费一区| 三级片免费观看久久| 国产精品久久久久免费a∨|