我们从Python开源项目中,提取了以下9个代码示例,用于说明如何使用scipy.cos()。
def loss(r_0, a, alpha, x_focus, x, y_focus, y, overlap): loss = np.zeros(np.size(x)) loss_squared = np.zeros(np.size(x)) dx = np.zeros(len(x)) dy = np.zeros(len(y)) for i in range(0, np.size(x)): dx = x_focus-x[i] dy = abs(y_focus-y[i]) R = r_0[i]+dx*alpha if dx > 0: loss[i] = overlap[i]*2.*a*(r_0[i]/(r_0[i]+alpha*(dx)))**2*0.5*(np.cos(-dy*pi/(R+4*r_0[i]))) loss_squared[i] = loss[i]**2 else: loss[i] = 0 loss_squared[i] = 0 total_loss = sp.sqrt(np.sum(loss_squared)) return total_loss
def rvs( self ): if self.ss == 0: x = random.random() * self.w y = random.random() * self.h self.set_point( x, y ) while self.qs: x_idx = int( random.random() * self.qs ) s = self.queue[ x_idx ] for y_idx in range( self.n ): a = 2 * scipy.pi * random.random() b = scipy.sqrt( self.A * random.random() + self.r2 ) x = s[0] + b*scipy.cos( a ) y = s[1] + b*scipy.sin( a ) if( x >= 0 )and( x < self.w ): if( y >= 0 )and( y < self.h ): if( self.distance( x, y ) ): self.set_point( x, y ) del self.queue[x_idx] self.qs -= 1 sample = list( filter( None, self.grid ) ) sample = scipy.asfarray( sample ) return sample
def model(THETA, time, kplanets): modelo = 0.0 if kplanets == 0: return 0.0 for i in range(kplanets): As, P, Ac, S, C = THETA[5*i:5*(i+1)] A = As ** 2 + Ac ** 2 ecc = S ** 2 + C ** 2 w = sp.arccos(C / (ecc ** 0.5)) # longitude of periastron phase = sp.arccos(Ac / (A ** 0.5)) ### test if S < 0: w = 2 * sp.pi - sp.arccos(C / (ecc ** 0.5)) if As < 0: phase = 2 * sp.pi - sp.arccos(Ac / (A ** 0.5)) ### per = sp.exp(P) freq = 2. * sp.pi / per M = freq * time + phase E = sp.array([MarkleyKESolver().getE(m, ecc) for m in M]) f = (sp.arctan(((1. + ecc) ** 0.5 / (1. - ecc) ** 0.5) * sp.tan(E / 2.)) * 2.) modelo += A * (sp.cos(f + w) + ecc * sp.cos(w)) return modelo
def rotate(x, y, U_direction_radians): x_r = x*np.cos(U_direction_radians)-y*np.sin(U_direction_radians) y_r = x*np.sin(U_direction_radians)+y*np.cos(U_direction_radians) return x_r, y_r
def ellipse2bbox(a, b, angle, cx, cy): a, b = max(a, b), min(a, b) ca = sp.cos(angle) sa = sp.sin(angle) if sa == 0.0: cta = 2.0 / sp.pi else: cta = ca / sa if ca == 0.0: ta = sp.pi / 2.0 else: ta = sa / ca x = lambda t: cx + a * sp.cos(t) * ca - b * sp.sin(t) * sa y = lambda t: cy + b * sp.sin(t) * ca + a * sp.cos(t) * sa # x = cx + a * cos(t) * cos(angle) - b * sin(t) * sin(angle) # tan(t) = -b * tan(angle) / a tx1 = sp.arctan(-b * ta / a) tx2 = tx1 - sp.pi x1, y1 = x(tx1), y(tx1) x2, y2 = x(tx2), y(tx2) # y = cy + b * sin(t) * cos(angle) + a * cos(t) * sin(angle) # tan(t) = b * cot(angle) / a ty1 = sp.arctan(b * cta / a) ty2 = ty1 - sp.pi x3, y3 = x(ty1), y(ty1) x4, y4 = x(ty2), y(ty2) minx, maxx = Util.minmax([x1, x2, x3, x4]) miny, maxy = Util.minmax([y1, y2, y3, y4]) return sp.floor(minx), sp.floor(miny), sp.ceil(maxx), sp.ceil(maxy)
def read_band(fileObj,key,b,d): '''reads MODIS data,scale them with the Solar Zenith and returns one band''' print 'read image '+str(b)+' from dataset '+str(key) +'... ' dsObj=fileObj.select(key) B=sp.array(dsObj.get(),sp.float32) # float32 attr=dsObj.attributes() scale=attr['reflectance_scales'][b] offset=attr['reflectance_offsets'][b] dn=B[b,:,:] bad_ind=(dn>=32767).nonzero() # Bit16 zeigt fehlerhafte Messungen an band=(scale*(dn-offset))/sp.cos(d['SolarZenith']) band[bad_ind]=0 print ' done' return band
def get_resolution(): EARTH_CIRCUMFERENCE = 40000 RES = .1 LAT_RES = 360*RES/EARTH_CIRCUMFERENCE CIRCUM_AT_LATITUDE = EARTH_CIRCUMFERENCE*sp.cos(sp.pi/180*LONDON_LATS[0]) LON_RES = 360*RES/CIRCUM_AT_LATITUDE return (LON_RES, LAT_RES)
def semimodel(self, params, time): A, P, phase, w, ecc = params freq = 2. * sp.pi / P M = freq * time + phase E = sp.array([MarkleyKESolver().getE(m, ecc) for m in M]) f = (sp.arctan(((1. + ecc) ** 0.5 / (1. - ecc) ** 0.5) * sp.tan(E / 2.)) * 2.) modelo = A * (sp.cos(f + w) + ecc * sp.cos(w)) return modelo
def DoAction(self, a, s): #MountainCarDoAction: executes the action (a) into the mountain car # acti: is the force to be applied to the car # x: is the vector containning the position and speed of the car # xp: is the vector containing the new position and velocity of the car #print('action',a) #print('state',s) # if a[0]>0.1: # force = 1 # elif a[0]<-0.1: # force = -1 # else: # force = 0 force = min(max(a[0], -1.0), 1.0) self.steps = self.steps + 1 position = s[0] speed = s[1] #print position, speed # bounds for position bpleft = -1.4 # bounds for speed bsleft = -0.07 bsright = 0.07 speedt1 = speed + (self.power * force) + (-0.0025 * cos(3.0 * position)) #print speedt1 if speedt1 < bsleft: speedt1 = bsleft elif speedt1 > bsright: speedt1 = bsright post1 = position + speedt1 if post1 <= bpleft: post1 = bpleft speedt1 = 0.0 #print post1, speedt1 return [post1, speedt1]