锘??xml version="1.0" encoding="utf-8" standalone="yes"?>久久综合色之久久综合,精品综合久久久久久97超人,欧美日韩精品久久久久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%錛岀浜屼釜綆卞瓙鍐呮湁鍥涗釜鑻規(guī)灉錛宭abel涓篵鐨勬鐜?0%,label 涓篴鐨勬鐜?0%.
濡傛灉鎴戜滑姹傛墍鏈夌殑鑻規(guī)灉鐨勯噸閲忥紝鍙渶瑕佸皢鎵鏈夌殑綆卞瓙鍐呯殑鑻規(guī)灉鍙栧嚭鏉ユ眰閲嶉噺鍗沖埢銆?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 瀹氫箟鏂規(guī)硶鏄?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鏂規(guī)硶

Python鐨刣ictionary
key -value瀵瑰簲
value鍙互鏄竴涓猯ist
娉ㄦ剰鏂規(guī)嫭鍙穂]閲岄潰鍙兘浣跨敤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綾葷殑瀹氫箟鍜岀被鏂規(guī)硶鐨勫畾涔?br />瀹氫箟綾諱笉闇瑕佺敤def class,鐩存帴

class ClassName(object):
姣忎釜綾婚兘鏈?__init__(self,arg):
鏂規(guī)硶錛屾敞鎰忔槸 宸﹀彸鍚勪袱涓笅鍒掔嚎錛屾誨叡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 鍙戣〃璇勮
]]>
久久久久久午夜精品| 国产精品狼人久久久久影院 | 日韩亚洲欧美久久久www综合网| 久久99精品久久久久久hb无码| 九九99精品久久久久久| 久久精品国产一区二区电影| 亚洲人成无码久久电影网站| 久久亚洲美女精品国产精品| 久久精品亚洲福利| 综合网日日天干夜夜久久| 久久高清一级毛片| 久久久久国产精品熟女影院| 青青草国产97免久久费观看| 99久久国产热无码精品免费| 久久婷婷色香五月综合激情| 国产精品成人精品久久久| 久久久久亚洲av无码专区导航| 色婷婷久久久SWAG精品| 欧美777精品久久久久网| av色综合久久天堂av色综合在| 久久精品成人免费国产片小草| av无码久久久久久不卡网站| 久久久久久久97| 99久久综合国产精品免费| 久久久WWW成人| 久久亚洲国产精品123区| 9999国产精品欧美久久久久久 | 亚洲国产精品无码久久久蜜芽 | 久久久WWW成人免费毛片| 成人国内精品久久久久一区| 久久亚洲美女精品国产精品| 中文字幕无码久久人妻| 亚洲国产成人久久精品99| 精品久久久久久久久久中文字幕| 国内精品久久久久影院免费| 久久精品国产亚洲AV高清热| AV无码久久久久不卡蜜桃 | 亚洲欧美成人综合久久久| 99精品国产免费久久久久久下载| 国产精品久久久99| 午夜福利91久久福利|