def __init__(self, dispersion, wvls): """Initialize an instance of N_mixture class to store the index of refraction of a mixture with constant dispersion This method takes 2 arguments: material an instance of a mixture dispersion class; wvls the wavelengths at which to calculate the index of refraction.""" self.wvls = wvls self.dispersion = dispersion if isinstance(self.dispersion, constant_mixture): self.f_N = self.dispersion.set_N_constant_mixture self.f_N_x = self.dispersion.set_N_constant_mixture_by_x self.f_dN = self.dispersion.set_dN_constant_mixture elif isinstance(self.dispersion, table_mixture): self.f_N = self.dispersion.set_N_table_mixture self.f_N_x = self.dispersion.set_N_table_mixture_by_x self.f_dN = self.dispersion.set_dN_table_mixture elif isinstance(self.dispersion, Cauchy_mixture): self.f_N = self.dispersion.set_N_Cauchy_mixture self.f_N_x = self.dispersion.set_N_Cauchy_mixture_by_x self.f_dN = self.dispersion.set_dN_Cauchy_mixture elif isinstance(self.dispersion, Sellmeier_mixture): self.f_N = self.dispersion.set_N_Sellmeier_mixture self.f_N_x = self.dispersion.set_N_Sellmeier_mixture_by_x self.f_dN = self.dispersion.set_dN_Sellmeier_mixture self.N = N(self.wvls) self.dN = N(self.wvls) self.length = 0 self.N_graded = None
def _chiSquare_old(model, parameters, data): n_param = len(parameters) chi_sq = 0. alpha = N.zeros((n_param, n_param)) for point in data: sigma = 1 if len(point) == 3: sigma = point[2] f = model(parameters, point[0]) chi_sq = chi_sq + ((f - point[1]) / sigma)**2 d = N.array(f[1]) / sigma alpha = alpha + d[:, N.NewAxis] * d return chi_sq, alpha
def _chiSquare_old(model, parameters, data): n_param = len(parameters) chi_sq = 0. alpha = N.zeros((n_param, n_param)) for point in data: sigma = 1 if len(point) == 3: sigma = point[2] f = model(parameters, point[0]) chi_sq = chi_sq + ((f-point[1])/sigma)**2 d = N.array(f[1])/sigma alpha = alpha + d[:,N.NewAxis]*d return chi_sq, alpha
def buildTree(parser, depth, dir_name, filestart=None): if not filestart is None: tree = N.findFile(filestart, parser, dir_name=dir_name) else: tree = N.Node(directory=dir_name) old_index = parser.index while not parser.atEnd() and tree.utility.count < depth: inst = parser.getNext() N.addInc(tree, inst) if not filestart is None and parser.index >= old_index * 2: tree.saveObject(filestart+str(parser.index)+'.cbwb', remove=filestart+str(old_index)+'.cbwb') old_index = parser.index if not filestart is None: tree.saveObject(filestart+str(parser.index)+'.cbwb', remove=filestart+str(old_index)+'.cbwb') return tree
def prepare_N_mixture_graded(self, length): """Prepare a mixture index instance to represent graded-index layers This method takes 1 argument: length the number of index levels to prepare.""" self.length = length self.N_graded = [N(self.wvls) for i in range(self.length)]
def h_prima(edad, sexo, tiempo_exposicion, nivel_exposicion, fractil): """ Esta función recibe como parámetros de entrada -> edad,sexo,tiempo_exposicion, nivel_exposicion, fractil <- para calcular el RIESGO DE PÉRDIDA AUDITIVA OCASIONADO POR EL RUIDO. Retorna una lista de tuplas que tienen la siguiente configuración: (frecuencia, valor) """ h = H.h(edad,sexo,fractil) n = N.n(tiempo_exposicion, nivel_exposicion, fractil) return (rechaza_frecuencias(interpolando(calculo_h_prima(h,n))))
def __init__(self, num, denum=N(1)): if isinstance(num, N): self.num = num.toZ() elif isinstance(num, Z): self.num = num else: self.num = Z(num) if isinstance(denum, Z): if denum.sign: self.num = self.num * Z(-1) self.denum = abs(denum).toN() elif isinstance(denum, N): self.denum = denum else: self.denum = N(denum) # self.num = num # Числитель. # self.denum = denum # Знаменатель. if self.denum == N(0): raise ZeroDivisionError("Divided by zero")
def _chiSquare(model, parameters, data): # assume: data is a nx3 numpy array. n_param = len(parameters) chi_sq = 0. alpha = N.zeros((n_param, n_param)) flist=model(parameters, data[:,0]) if data.shape[1]<3: silist=np.ones(data.shape[0]) else: silist=data[:,2] if data.shape[0]==1: flist=[flist] for i in range(data.shape[0]): f=flist[i] sigma=silist[i] #print(type(f)) #print(type(data)) chi_sq = chi_sq + ((f-data[i,1])/sigma)**2 d = N.array(f[1])/sigma alpha = alpha + d[:,N.NewAxis]*d return chi_sq, alpha
def _chiSquare(model, parameters, data): # assume: data is a nx3 numpy array. n_param = len(parameters) chi_sq = 0. alpha = N.zeros((n_param, n_param)) flist = model(parameters, data[:, 0]) if data.shape[1] < 3: silist = np.ones(data.shape[0]) else: silist = data[:, 2] if data.shape[0] == 1: flist = [flist] for i in range(data.shape[0]): f = flist[i] sigma = silist[i] #print(type(f)) #print(type(data)) chi_sq = chi_sq + ((f - data[i, 1]) / sigma)**2 d = N.array(f[1]) / sigma alpha = alpha + d[:, N.NewAxis] * d return chi_sq, alpha
async def _create_welcome(O,member,test_member_number:I=E): AR='of ';AQ='Welcome';q=test_member_number;K=member;C=await O.config.guild(K.guild).all();AD=C[g];AE=C[h];AF=C[e];AG=C[f];T=C[Z];AH=C[a];AI=C[b];AJ=C[c];AK=C[d];r=G.truetype(AD,AE);U=G.truetype(AF,AG);s=G.truetype(T,AH);t=G.truetype(T,AI);u=G.truetype(T,AJ);v=G.truetype(T,AK);w=F.open(C[A7]).convert(S);AL=F.open(O.imgpath+'/noimage.png');L=F.new(S,(500,150));L=n.fit(w,(500,150),centering=(0.5,0.5));L.paste(w);L=L.resize((500,150),F.NEAREST);V=F.new('L',(512,512),0);AM=R.Draw(V);AM.ellipse(((0,0),(512,512)),fill=255);i=J(C[A9]);V=V.resize(i,F.ANTIALIAS) try:P=m();await K.avatar_url.save(P,seek_begin=A);P=F.open(P).convert(S) except A4 as AS:o.error('ImgWelcome error in create_welcome:\n',exc_info=A);P=AL j=n.fit(P,i,centering=(0,0));j.putalpha(V);k=J(C[A8]);W=J(C[p]);x=J(C[AB]) try:y=J(C[AC]) except A5:y=J(C[p]) M=J(C[AA]);z=F.new('L',(512,512),0);AN=R.Draw(z);AN.ellipse((0,0)+(512,512),fill=255,outline=0);X=F.new(S,(512,512));AO=R.Draw(X);AO.ellipse([0,0,512,512],fill=(k[0],k[1],k[2],180),outline=(255,255,255,250));Y=await O._circle_border(i);X=X.resize(Y,F.ANTIALIAS);AP=z.resize(Y,F.ANTIALIAS);A0=7+I((136-Y[0])/2);A1=11+I((136-Y[0])/2);H=R.Draw(L);L.paste(X,(A0,A0),AP);L.paste(j,(A1,A1),j);E=B(K) def N(original_position:J,text:B,pixel_displacement:I,font,textoutline):D=textoutline;C=font;B=text;A=original_position;E=pixel_displacement;F=A[0]-E,A[1];G=A[0]+E,A[1];I=A[0],A[1]-E;J=A[0],A[1]+E;H.text(F,B,font=C,fill=D);H.text(G,B,font=C,fill=D);H.text(I,B,font=C,fill=D);H.text(J,B,font=C,fill=D);H.text(A,B,font=C,fill=D) N((150,16),AQ,1,r,M);H.text((150,16),AQ,font=r,fill=y) if D(E)<=17:N((152,63),E,1,s,M);H.text((152,63),E,font=s,fill=W) if D(E)>17: if D(E)<=23:N((152,66),E,1,t,M);H.text((152,66),E,font=t,fill=W) if D(E)>=24: if D(E)<=32:N((152,70),E,1,u,M);H.text((152,70),E,font=u,fill=W) if D(E)>=33:N((152,73),E,1,v,M);H.text((152,73),E,font=v,fill=W) if not q: if not O.bot.intents.members:Q=K.guild.member_count+1 else: try:Q=A6(K.guild.members,key=lambda m:m.joined_at).index(K)+1 except A5:Q=K.guild.member_count+1 else:Q=I(q) A2=B(Q)+O._get_suffix(Q);A3=B(K.guild.name)+'!'if D(B(K.guild.name))<=28 else B(K.guild.name)[:23]+'...';N((152,96),f"You are the {B(A2)} member",1,U,M);H.text((152,96),f"You are the {B(A2)} member",font=U,fill=x);N((152,116),AR+A3,1,U,M);H.text((152,116),AR+A3,font=U,fill=x);l=m();L.save(l,format='PNG');l.seek(0);return l
def tryReverseOp(a, b, op): crutch = {type(N(0)): 1, type(Z(0)): 2, type(Q(0)): 3, type(poly(0)): 4 } # print( type( a ), type( b ) ) # print( type(N(0)), type(Z(0)), type(Q(0)), type(poly(0)) ) # print( a, op, b, ": ", type( a ), type( b ) ) # print( self, "__add__", other, ": ", type( self ), type( other ) ) try: if crutch[type(a)] < crutch[type(b)]: return eval('type(b)(a)' + op + 'b') else: # print( str( a ) + op + str( eval( "type(a)(b)" ) ) ) return eval("a" + op + 'type(a)(b)') except: print(a, op, b, ": ", type(a), type(b)) raise RuntimeError
result = search_result print(api.rate_limit_status()['resources']['search']['/search/tweets']) return result if __name__ == "__main__": word = input(">>") all_word = [] # 書き込みモードで出力 f = open("text.txt", "a") # すべてのtextから名詞を抽出 for r in search(word): #print(r.text) all_word = all_word + N.collect(r.text) f.write(r.text) # textの書き出し top10_word = [] for t in N.count(all_word): #print(t[0]) top10_word.append(t[0]) # 数の多い上位50個に関するtextを再度集める for aw in top10_word: print(aw) for r2 in search(aw): f.write(r2.text) f.close()
def leastSquaresFit(model, parameters, data, max_iterations=None, stopping_limit = 0.005): """General non-linear least-squares fit using the X{Levenberg-Marquardt} algorithm and X{automatic differentiation}. @param model: the function to be fitted. It will be called with two parameters: the first is a tuple containing all fit parameters, and the second is the first element of a data point (see below). The return value must be a number. Since automatic differentiation is used to obtain the derivatives with respect to the parameters, the function may only use the mathematical functions known to the module FirstDerivatives. @type model: callable @param parameters: a tuple of initial values for the fit parameters @type parameters: C{tuple} of numbers @param data: a list of data points to which the model is to be fitted. Each data point is a tuple of length two or three. Its first element specifies the independent variables of the model. It is passed to the model function as its first parameter, but not used in any other way. The second element of each data point tuple is the number that the return value of the model function is supposed to match as well as possible. The third element (which defaults to 1.) is the statistical variance of the data point, i.e. the inverse of its statistical weight in the fitting procedure. @type data: C{list} @returns: a list containing the optimal parameter values and the chi-squared value describing the quality of the fit @rtype: C{(list, float)} """ n_param = len(parameters) p = () i = 0 for param in parameters: p = p + (DerivVar(param, i),) i = i + 1 id = N.identity(n_param) l = 0.001 chi_sq, alpha = _chiSquare(model, p, data) niter = 0 while 1: delta = LA.solve_linear_equations(alpha+l*N.diagonal(alpha)*id, -0.5*N.array(chi_sq[1])) next_p = map(lambda a,b: a+b, p, delta) next_chi_sq, next_alpha = _chiSquare(model, next_p, data) if next_chi_sq > chi_sq: l = 10.*l else: l = 0.1*l if chi_sq[0] - next_chi_sq[0] < stopping_limit: break p = next_p chi_sq = next_chi_sq alpha = next_alpha niter = niter + 1 if max_iterations is not None and niter == max_iterations: #raise IterationCountExceededError print('Max iterations reach. Returning values.') break return [p[0] for p in next_p], next_chi_sq[0]
async def _create_welcome(O, member, test_member_number: I = E): AR = 'to ' AQ = 'Welcome' q = test_member_number K = member C = await O.config.guild(K.guild).all() AD = C[g] AE = C[h] AF = C[e] AG = C[f] T = C[Z] AH = C[a] AI = C[b] AJ = C[c] AK = C[d] r = G.truetype(AD, AE) U = G.truetype(AF, AG) s = G.truetype(T, AH) t = G.truetype(T, AI) u = G.truetype(T, AJ) v = G.truetype(T, AK) w = F.open(C[A7]).convert(S) AL = F.open(O.imgpath + '/noimage.png') L = F.new(S, (500, 150)) L = n.fit(w, (500, 150), centering=(0.5, 0.5)) L.paste(w) L = L.resize((500, 150), F.NEAREST) V = F.new('L', (512, 512), 0) AM = R.Draw(V) AM.ellipse(((0, 0), (512, 512)), fill=255) i = J(C[A9]) V = V.resize(i, F.ANTIALIAS) try: P = m() await K.avatar_url.save(P, seek_begin=A) P = F.open(P).convert(S) except A4 as AS: o.error('ImgWelcome error in create_welcome:\n', exc_info=A) P = AL j = n.fit(P, i, centering=(0, 0)) j.putalpha(V) k = J(C[A8]) W = J(C[p]) x = J(C[AB]) try: y = J(C[AC]) except A5: y = J(C[p]) M = J(C[AA]) z = F.new('L', (512, 512), 0) AN = R.Draw(z) AN.ellipse((0, 0) + (512, 512), fill=255, outline=0) X = F.new(S, (512, 512)) AO = R.Draw(X) AO.ellipse([0, 0, 512, 512], fill=(k[0], k[1], k[2], 180), outline=(255, 255, 255, 250)) Y = await O._circle_border(i) X = X.resize(Y, F.ANTIALIAS) AP = z.resize(Y, F.ANTIALIAS) A0 = 7 + I((136 - Y[0]) / 2) A1 = 11 + I((136 - Y[0]) / 2) H = R.Draw(L) L.paste(X, (A0, A0), AP) L.paste(j, (A1, A1), j) E = B(K) def N(original_position: J, text: B, pixel_displacement: I, font, textoutline): D = textoutline C = font B = text A = original_position E = pixel_displacement F = A[0] - E, A[1] G = A[0] + E, A[1] I = A[0], A[1] - E J = A[0], A[1] + E H.text(F, B, font=C, fill=D) H.text(G, B, font=C, fill=D) H.text(I, B, font=C, fill=D) H.text(J, B, font=C, fill=D) H.text(A, B, font=C, fill=D) N((150, 16), AQ, 1, r, M) H.text((150, 16), AQ, font=r, fill=y) if D(E) <= 17: N((152, 63), E, 1, s, M) H.text((152, 63), E, font=s, fill=W) if D(E) > 17: if D(E) <= 23: N((152, 66), E, 1, t, M) H.text((152, 66), E, font=t, fill=W) if D(E) >= 24: if D(E) <= 32: N((152, 70), E, 1, u, M) H.text((152, 70), E, font=u, fill=W) if D(E) >= 33: N((152, 73), E, 1, v, M) H.text((152, 73), E, font=v, fill=W) if not q: if not O.bot.intents.members: Q = K.guild.member_count + 1 else: try: Q = A6(K.guild.members, key=lambda m: m.joined_at).index(K) + 1 except A5: Q = K.guild.member_count + 1 else: Q = I(q) A2 = B(Q) + O._get_suffix(Q) A3 = B(K.guild.name) + '!' if D(B( K.guild.name)) <= 28 else B(K.guild.name)[:23] + '...' N((152, 109), AR + A3, 1, U, M) H.text((152, 109), AR + A3, font=U, fill=x) l = m() L.save(l, format='PNG') l.seek(0) return l
def leastSquaresFit(model, parameters, data, max_iterations=None, stopping_limit=0.005): """General non-linear least-squares fit using the X{Levenberg-Marquardt} algorithm and X{automatic differentiation}. @param model: the function to be fitted. It will be called with two parameters: the first is a tuple containing all fit parameters, and the second is the first element of a data point (see below). The return value must be a number. Since automatic differentiation is used to obtain the derivatives with respect to the parameters, the function may only use the mathematical functions known to the module FirstDerivatives. @type model: callable @param parameters: a tuple of initial values for the fit parameters @type parameters: C{tuple} of numbers @param data: a list of data points to which the model is to be fitted. Each data point is a tuple of length two or three. Its first element specifies the independent variables of the model. It is passed to the model function as its first parameter, but not used in any other way. The second element of each data point tuple is the number that the return value of the model function is supposed to match as well as possible. The third element (which defaults to 1.) is the statistical variance of the data point, i.e. the inverse of its statistical weight in the fitting procedure. @type data: C{list} @returns: a list containing the optimal parameter values and the chi-squared value describing the quality of the fit @rtype: C{(list, float)} """ n_param = len(parameters) p = () i = 0 for param in parameters: p = p + (DerivVar(param, i), ) i = i + 1 id = N.identity(n_param) l = 0.001 chi_sq, alpha = _chiSquare(model, p, data) niter = 0 while 1: delta = LA.solve_linear_equations(alpha + l * N.diagonal(alpha) * id, -0.5 * N.array(chi_sq[1])) next_p = map(lambda a, b: a + b, p, delta) next_chi_sq, next_alpha = _chiSquare(model, next_p, data) if next_chi_sq > chi_sq: l = 10. * l else: l = 0.1 * l if chi_sq[0] - next_chi_sq[0] < stopping_limit: break p = next_p chi_sq = next_chi_sq alpha = next_alpha niter = niter + 1 if max_iterations is not None and niter == max_iterations: #raise IterationCountExceededError print('Max iterations reach. Returning values.') break return [p[0] for p in next_p], next_chi_sq[0]
async def _create_welcome(R, member, test_member_number: I = E): AQ = 'of ' AP = 'Welcome' q = test_member_number K = member C = await R.config.guild(K.guild).all() AC = C[f] AD = C[g] AE = C[d] AF = C[e] S = C[Y] AG = C[Z] AH = C[a] AI = C[b] AJ = C[c] r = G.truetype(AC, AD) T = G.truetype(AE, AF) s = G.truetype(S, AG) t = G.truetype(S, AH) u = G.truetype(S, AI) v = G.truetype(S, AJ) w = F.open(C[A6]).convert(Q) AK = F.open(R.imgpath + '/noimage.png') L = F.new(Q, (500, 150)) L = n.fit(w, (500, 150), centering=(0.5, 0.5)) L.paste(w) L = L.resize((500, 150), F.NEAREST) U = F.new('L', (512, 512), 0) AL = P.Draw(U) AL.ellipse(((0, 0), (512, 512)), fill=255) h = J(C[A8]) U = U.resize(h, F.ANTIALIAS) try: O = m() await K.avatar_url.save(O, seek_begin=A) O = F.open(O).convert(Q) except A4 as AR: o.error('ImgWelcome error in create_welcome:\n', exc_info=A) O = AK i = n.fit(O, h, centering=(0, 0)) i.putalpha(U) j = J(C[A7]) V = J(C[p]) x = J(C[AA]) try: y = J(C[AB]) except TypeError: y = J(C[p]) M = J(C[A9]) z = F.new('L', (512, 512), 0) AM = P.Draw(z) AM.ellipse((0, 0) + (512, 512), fill=255, outline=0) W = F.new(Q, (512, 512)) AN = P.Draw(W) AN.ellipse([0, 0, 512, 512], fill=(j[0], j[1], j[2], 180), outline=(255, 255, 255, 250)) X = await R._circle_border(h) W = W.resize(X, F.ANTIALIAS) AO = z.resize(X, F.ANTIALIAS) A0 = 7 + I((136 - X[0]) / 2) A1 = 11 + I((136 - X[0]) / 2) H = P.Draw(L) L.paste(W, (A0, A0), AO) L.paste(i, (A1, A1), i) E = f"{B(K)}" def N(original_position: J, text: B, pixel_displacement: I, font, textoutline): D = textoutline C = font B = text A = original_position E = pixel_displacement F = A[0] - E, A[1] G = A[0] + E, A[1] I = A[0], A[1] - E J = A[0], A[1] + E H.text(F, B, font=C, fill=D) H.text(G, B, font=C, fill=D) H.text(I, B, font=C, fill=D) H.text(J, B, font=C, fill=D) H.text(A, B, font=C, fill=D) N((150, 16), AP, 1, r, M) H.text((150, 16), AP, font=r, fill=y) if D(E) <= 17: N((152, 63), E, 1, s, M) H.text((152, 63), E, font=s, fill=V) if D(E) > 17: if D(E) <= 23: N((152, 66), E, 1, t, M) H.text((152, 66), E, font=t, fill=V) if D(E) >= 24: if D(E) <= 32: N((152, 70), E, 1, u, M) H.text((152, 70), E, font=u, fill=V) if D(E) >= 33: N((152, 73), E, 1, v, M) H.text((152, 73), E, font=v, fill=V) if not q: k = A5(K.guild.members, key=lambda m: m.joined_at).index(K) + 1 else: k = I(q) A2 = B(k) + R._get_suffix(k) A3 = B(K.guild.name) + '!' if D(B( K.guild.name)) <= 28 else B(K.guild.name)[:23] + '...' N((152, 96), f"You are the {B(A2)} member", 1, T, M) H.text((152, 96), f"You are the {B(A2)} member", font=T, fill=x) N((152, 116), AQ + A3, 1, T, M) H.text((152, 116), AQ + A3, font=T, fill=x) l = m() L.save(l, format='PNG') l.seek(0) return l
-can be used to compute basis set for a general function f by checking all possible frequencies -don't have to do it for all phases since any phase can be given by weighted sum of integral with sin and cos Fourier Transfor, More Formal -see 2C-L1, video 9 Frequency Spectra -largely only look at |F(w)| -power spectra tends to fall off at higher frequency (for any natural signal) Limitations -Fourier transform, F(w) exists if integral from -inf to inf of |f(x)| exists -if there's an interval T outside of which f is 0, can only do Fourier transform integral on interval Discrete Fourier Transform -see 2C-L1, video 12 -discrete frequency k (cycles per image/interval) can only go from -N/2 to N/2 since min period is 2 (1 sample high, 1 sample low) so number of cycles over N (frequency) would be N/2 2D Fourier Transform -see 2C-L1, video 13 Examples -removing high frequency -ringing- ripples from not having high frequency to smooth image -removing low frequency -gives edges -sharpening filter -accentuate high frequencies -pictures with a lot of angled lines leads to higher magnitude lines in frequency spectrum perpendicular to direction of lines in original image -essentually assumes that image continues periodically past acutal bouds -gives high magnitude line in vertical direction from the Transform "sticking" top and bottom edges together
def func(): ...do something else... # O.py from M import func from N import func # This overwites the one we got from M func() # Calls N.func only # O.py import M, N # Get the whole modules, not their names M.func() # We can call both names now N.func() # The module names make them unique ### file: module2.py print('starting to load...') import sys name = 42 def func(): pass class klass: pass print('done loading.')
def toN(self): if (self.isZ() and (self.num // self.denum >= Z(0))): return N(str(self.num // self.denum)) else: raise RuntimeError("Z", str(self), "cannot be presented as N.")
# import가 필요한 경우 # M.py def func(): ...무엇인가를 수행함... # N.py def func(): ...다른 무엇인가를 수행함... # O.py from M import func from N import func # M으로부터 가져온 func를 덮어씀 func() # N.func만 호출함 # O.py import M, N # 모듈의 이름들이 아니라, 전체 모듈을 가져옴 M.func() # 이제 두 이름 모두 호출할 수 있음 N.func() # 모듈 이름이 두 이름을 유일하게 만들어줌 # O.py from M import func as mfunc # "as"를 이용하여 이름을 유일하게 재명명 from N import func as nfunc mfunc(), nfunc(); # 하나 또는 나머지의 하나를 호출함
print(beads[0]) start = time.time() for i in range(100): T.XYZ(beads, img) ts.append(time.time() - start) plt.plot(loopRange, np.array(ts), marker="o", label="GPU - Taichi") print(np.polynomial.polynomial.polyfit(loopRange[1:], ts[1:], 1)) if (True): ts = [] for loop in loopRange: beads = [] for i in range(loop): beads.append(N.Bead(50, 50)) N.XY(beads, img) for i in range(20): N.Calibrate(beads, [imgc[i]], i) N.ComputeCalibration(beads) N.XYZ(beads, img) print(beads[0]) start = time.time() for i in range(100): N.XYZ(beads, img) ts.append(time.time() - start)
from N import * from Z import * from Q import * from poly import * #poly = polynom( [ N([0]), N([3]), N([0]), Z([-1]) ] ) #print( "f(x) =", poly ) print(N([1, 3])) q1 = Q(Z([2]), N(1)) print("Hello world!") q1 = Q(Z(-24), N(142))
import numpy as np import matplotlib.pyplot as plt import time, mm, utils import N as T beads = [] zcs = np.arange(0, 5000, 50) circles = utils.HoughCircles(mm.Get(), 15, 30) # for c in circles: # if (c[0] > 80 and c[0] < 680 and c[1] > 80 and c[1] < 500): # beads.append(T.Bead(c[0], c[1])) beads = [ T.Bead(circles[0][0], circles[0][1]), T.Bead(circles[1][0], circles[1][1]) ] n = len(beads) print(n, "Beads:", beads) sz = mm.GetZ() T.XY(beads, mm.Get()) # calibrate imgc = [] for z in zcs: imgc.append([]) for t in range(3): for i in range(len(zcs)): z = zcs[i]
# exit() dir('d:/test/t.py') DIH=DINT_HEX=INT_HEX={0:'00',1:'01',2:'02',3:'03',4:'04',5:'05',6:'06',7:'07',8:'08',9:'09',10:'0A',11:'0B',12:'0C',13:'0D',14:'0E',15:'0F',16:'10',17:'11',18:'12',19:'13',20:'14',21:'15',22:'16',23:'17',24:'18',25:'19',26:'1A',27:'1B',28:'1C',29:'1D',30:'1E',31:'1F',32:'20',33:'21',34:'22',35:'23',36:'24',37:'25',38:'26',39:'27',40:'28',41:'29',42:'2A',43:'2B',44:'2C',45:'2D',46:'2E',47:'2F',48:'30',49:'31',50:'32',51:'33',52:'34',53:'35',54:'36',55:'37',56:'38',57:'39',58:'3A',59:'3B',60:'3C',61:'3D',62:'3E',63:'3F',64:'40',65:'41',66:'42',67:'43',68:'44',69:'45',70:'46',71:'47',72:'48',73:'49',74:'4A',75:'4B',76:'4C',77:'4D',78:'4E',79:'4F',80:'50',81:'51',82:'52',83:'53',84:'54',85:'55',86:'56',87:'57',88:'58',89:'59',90:'5A',91:'5B',92:'5C',93:'5D',94:'5E',95:'5F',96:'60',97:'61',98:'62',99:'63',100:'64',101:'65',102:'66',103:'67',104:'68',105:'69',106:'6A',107:'6B',108:'6C',109:'6D',110:'6E',111:'6F',112:'70',113:'71',114:'72',115:'73',116:'74',117:'75',118:'76',119:'77',120:'78',121:'79',122:'7A',123:'7B',124:'7C',125:'7D',126:'7E',127:'7F',128:'80',129:'81',130:'82',131:'83',132:'84',133:'85',134:'86',135:'87',136:'88',137:'89',138:'8A',139:'8B',140:'8C',141:'8D',142:'8E',143:'8F',144:'90',145:'91',146:'92',147:'93',148:'94',149:'95',150:'96',151:'97',152:'98',153:'99',154:'9A',155:'9B',156:'9C',157:'9D',158:'9E',159:'9F',160:'A0',161:'A1',162:'A2',163:'A3',164:'A4',165:'A5',166:'A6',167:'A7',168:'A8',169:'A9',170:'AA',171:'AB',172:'AC',173:'AD',174:'AE',175:'AF',176:'B0',177:'B1',178:'B2',179:'B3',180:'B4',181:'B5',182:'B6',183:'B7',184:'B8',185:'B9',186:'BA',187:'BB',188:'BC',189:'BD',190:'BE',191:'BF',192:'C0',193:'C1',194:'C2',195:'C3',196:'C4',197:'C5',198:'C6',199:'C7',200:'C8',201:'C9',202:'CA',203:'CB',204:'CC',205:'CD',206:'CE',207:'CF',208:'D0',209:'D1',210:'D2',211:'D3',212:'D4',213:'D5',214:'D6',215:'D7',216:'D8',217:'D9',218:'DA',219:'DB',220:'DC',221:'DD',222:'DE',223:'DF',224:'E0',225:'E1',226:'E2',227:'E3',228:'E4',229:'E5',230:'E6',231:'E7',232:'E8',233:'E9',234:'EA',235:'EB',236:'EC',237:'ED',238:'EE',239:'EF',240:'F0',241:'F1',242:'F2',243:'F3',244:'F4',245:'F5',246:'F6',247:'F7',248:'F8',249:'F9',250:'FA',251:'FB',252:'FC',253:'FD',254:'FE',255:'FF'} DHI=DHEX_INT=HEX_INT={y:x for x,y in DIH.iteritems()} if __name__=='__main__': # import T,U l=csvAsList('process.csv') # U.shtml(l) # print getSourcePath() exit() r=hexToBytes(T.HEX.lower()) # U.write('h.r',r) print bytesToHex(r) s='''%3Ctextarea+stylew3equalsign%22width%3A100%25%3Bheight%3A100%25%22%3Epublic+class+Int%7B%0D%0A%0D%0A%09public+static+void+main%28String%5B%5D+ays%29%7B%0D%0A%09%09int+aw3equalsignays.lengthw3equalsignw3equalsign1%3FInteger.valueOf%28ays%5B0%5D%29%3A%0D%0A%09%09%2F**xjw++a**%2F++2%3B%0D%0A%09%09%0D%0A%09%09for%28int+iw3equalsign0%2Csw3equalsign0%2Ctw3equalsign0%3Bi%3Ca%3Bi%2B%2B%29%7B%0D%0A%09%09%09t%2Bw3equalsigna*new+Object%28%29%7B%0D%0A%09%09%09%09int+pow%28int+a%2Cint+n%29%7B%0D%0A%09%09%09%09%09if%28nw3equalsignw3equalsign0%29return+1%3B%0D%0A%09%09%09%09%09if%28nw3equalsignw3equalsign1%29return+a%3B%0D%0A%09%09%09%09%09return+pow%28a%2Cn-1%29*a%3B%0D%0A%09%09%09%09%7D%09%0D%0A%09%09%09%7D.pow%2810%2Ci%29%3B%0D%0A%09%09%09s%2Bw3equalsignt%3B%0D%0A%09%09%09if%28iw3equalsignw3equalsigna-1%29System.out.printf%28%22a+w3equalsign+%25s%5Cns+w3equalsign+%25s%5Cn%22%2Ca%2Cs%29%3B%09%09%0D%0A%09%09%7D%0D%0A%09%7D%0D%0A%0D%0A%7D%3C%2Ftextarea%3E%0D%0A''' import T,N,U su='http://www.w3school.com.cn/tiy/v.asp?code=' for i in T.HEX: for j in T.HEX: url=su+'%'+i+j s=N.http(url) if len(s)>0: U.pln(url,c=s) exit()
search_result = api.search(q=txt, count=200) result = search_result print(api.rate_limit_status()['resources']['search']['/search/tweets']) return result if __name__ == "__main__": word = input(">>") all_word = [] # 書き込みモードで出力 f = open( "text.txt", "a" ) # すべてのtextから名詞を抽出 for r in search(word): #print(r.text) all_word = all_word + N.collect(r.text) f.write(r.text) # textの書き出し top10_word = [] for t in N.count(all_word): #print(t[0]) top10_word.append(t[0]) # 数の多い上位50個に関するtextを再度集める for aw in top10_word: print(aw) for r2 in search(aw): f.write(r2.text) f.close()
def _polynomialModel(params, t): r = 0.0 for i in range(len(params)): r = r + params[i]*N.power(t, i) return r
interpreter = argparse.ArgumentParser( description="Show the surpisingness of phones already added to the cluster hierarchy." ) interpreter.add_argument( "saveName", metavar="<begining_of_cbwb_file>", type=str, nargs=1, help="The part of the .cbwb file for this cluster which comes before the '_' (i.e. \"test\" if the cluster is saved as test_N.cbwb)", ) # interpreter.add_argument('-line', type=str, help='Show the line of average Surprise, Merges, Splits or Depth over time instead of regular output.') interpreter.add_argument( "-line", action="store_true", help="Show the line of average Surprise, Merges, Splits or Depth over time instead of regular output.", ) interpreter.add_argument("-csv", type=str, help="Save surprise values to csv file.") interpreter.add_argument( "-unscale", action="store_true", help="Unscale the attribute values of centroids when generating dot pictures" ) interpreter.set_defaults(showLine=False) args = interpreter.parse_args() tree = N.findFile(args.saveName[0] + "_", None) if args.csv: tree.viz.toCSV(args.csv) if args.line: tree.viz.surpriseLine() else: tree.viz.plotSurprise(unscale=args.unscale)
def _polynomialModel(params, t): r = 0.0 for i in range(len(params)): r = r + params[i] * N.power(t, i) return r