class A(object): def __init__(self, x): self.x = x def m(self): print(self.x)You are told to add a method to this interface (but you cannot edit the library source code). At runtime - do this:
def n(self): print(self.x) A.n = n a = A(2) a.n()
Things to do:
The 10 most common types cover almost 1/3 of the tokens, the top 1,000 cover just over 2/3.What do you observe on the much smaller big.txt corpus?
A Python decorator is any callable Python object that is used to modify a function, method or class definition. A decorator is passed the original object being defined and returns a modified object, which is then bound to the name in the definition. Python decorators were inspired in part by Java annotations, and have a similar syntax; the decorator syntax is pure syntactic sugar, using @ as the keyword:@viking_chorus def menu_item(): print("spam")is equivalent to:def menu_item(): print("spam") menu_item = viking_chorus(menu_item)
>>> import nltk >>> nltk <module 'nltk' from 'C:\Anaconda\lib\site-packages\nltk\__init__.py'> >>>
Things to do:
import numpy as np import matplotlib.pyplot as plt s = np.random.dirichlet((10, 5, 3), 20).transpose() plt.barh(range(20), s[0]) plt.barh(range(20), s[1], left=s[0], color='g') plt.barh(range(20), s[2], left=s[0]+s[1], color='r') plt.title("Lengths of Strings") plt.show()(About 2 hours)
μ ~ k1Beta(a, b) + k2Beta(c, d) where k1 + k2 = 1 m ~ Bin(μ N)A prior over μ of this form is called a mixture prior - as it is a linear combination of simple priors.
Things to do:
Things to do: