本文整理汇总了Python中numpy.core.umath.sqrt函数的典型用法代码示例。如果您正苦于以下问题:Python sqrt函数的具体用法?Python sqrt怎么用?Python sqrt使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sqrt函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_power_complex
def test_power_complex(self):
x = np.array([1+2j, 2+3j, 3+4j])
assert_equal(x**0, [1., 1., 1.])
assert_equal(x**1, x)
assert_equal(x**2, [-3+4j, -5+12j, -7+24j])
assert_equal(x**3, [(1+2j)**3, (2+3j)**3, (3+4j)**3])
assert_equal(x**4, [(1+2j)**4, (2+3j)**4, (3+4j)**4])
assert_almost_equal(x**(-1), [1/(1+2j), 1/(2+3j), 1/(3+4j)])
assert_almost_equal(x**(-2), [1/(1+2j)**2, 1/(2+3j)**2, 1/(3+4j)**2])
assert_almost_equal(x**(-3), [(-11+2j)/125, (-46-9j)/2197,
(-117-44j)/15625])
assert_almost_equal(x**(0.5), [ncu.sqrt(1+2j), ncu.sqrt(2+3j),
ncu.sqrt(3+4j)])
assert_almost_equal(x**14, [-76443+16124j, 23161315+58317492j,
5583548873 + 2465133864j])
# Ticket #836
def assert_complex_equal(x, y):
assert_array_equal(x.real, y.real)
assert_array_equal(x.imag, y.imag)
for z in [complex(0, np.inf), complex(1, np.inf)]:
z = np.array([z], dtype=np.complex_)
assert_complex_equal(z**1, z)
assert_complex_equal(z**2, z*z)
assert_complex_equal(z**3, z*z*z)
开发者ID:AndreI11,项目名称:SatStressGui,代码行数:26,代码来源:test_umath.py
示例2: test_power_complex
def test_power_complex(self):
x = np.array([1 + 2j, 2 + 3j, 3 + 4j])
assert_equal(x ** 0, [1.0, 1.0, 1.0])
assert_equal(x ** 1, x)
assert_almost_equal(x ** 2, [-3 + 4j, -5 + 12j, -7 + 24j])
assert_almost_equal(x ** 3, [(1 + 2j) ** 3, (2 + 3j) ** 3, (3 + 4j) ** 3])
assert_almost_equal(x ** 4, [(1 + 2j) ** 4, (2 + 3j) ** 4, (3 + 4j) ** 4])
assert_almost_equal(x ** (-1), [1 / (1 + 2j), 1 / (2 + 3j), 1 / (3 + 4j)])
assert_almost_equal(x ** (-2), [1 / (1 + 2j) ** 2, 1 / (2 + 3j) ** 2, 1 / (3 + 4j) ** 2])
assert_almost_equal(x ** (-3), [(-11 + 2j) / 125, (-46 - 9j) / 2197, (-117 - 44j) / 15625])
assert_almost_equal(x ** (0.5), [ncu.sqrt(1 + 2j), ncu.sqrt(2 + 3j), ncu.sqrt(3 + 4j)])
norm = 1.0 / ((x ** 14)[0])
assert_almost_equal(
x ** 14 * norm, [i * norm for i in [-76443 + 16124j, 23161315 + 58317492j, 5583548873 + 2465133864j]]
)
# Ticket #836
def assert_complex_equal(x, y):
assert_array_equal(x.real, y.real)
assert_array_equal(x.imag, y.imag)
for z in [complex(0, np.inf), complex(1, np.inf)]:
err = np.seterr(invalid="ignore")
z = np.array([z], dtype=np.complex_)
try:
assert_complex_equal(z ** 1, z)
assert_complex_equal(z ** 2, z * z)
assert_complex_equal(z ** 3, z * z * z)
finally:
np.seterr(**err)
开发者ID:jarrodmillman,项目名称:numpy,代码行数:30,代码来源:test_umath.py
示例3: moments
def moments(self, x, y, cut=0):
n = len(x)
inds = np.arange(n)
mx = np.mean(x)
my = np.mean(y)
x = x - mx
y = y - my
x2 = x * x
mxx = sum(x2) / n
y2 = y * y
myy = sum(y2) / n
xy = x * y
mxy = sum(xy) / n
emitt = sqrt(mxx * myy - mxy * mxy)
if cut > 0:
inds = []
beta = mxx / emitt
gamma = myy / emitt
alpha = mxy / emitt
emittp = gamma * x2 + 2. * alpha * xy + beta * y2
inds0 = np.argsort(emittp)
n1 = np.round(n * (100 - cut) / 100)
inds = inds0[0:n1]
mx = np.mean(x[inds])
my = np.mean(y[inds])
x1 = x[inds] - mx
y1 = y[inds] - my
mxx = np.sum(x1 * x1) / n1
myy = np.sum(y1 * y1) / n1
mxy = np.sum(x1 * y1) / n1
emitt = sqrt(mxx * myy - mxy * mxy)
return mx, my, mxx, mxy, myy, emitt
开发者ID:iagapov,项目名称:ocelot,代码行数:34,代码来源:beam.py
示例4: gauss_from_twiss
def gauss_from_twiss(emit, beta, alpha):
phi = 2*pi * np.random.rand()
u = np.random.rand()
a = sqrt(-2*np.log( (1-u)) * emit)
x = a * sqrt(beta) * cos(phi)
xp = -a / sqrt(beta) * ( sin(phi) + alpha * cos(phi) )
return (x, xp)
开发者ID:iagapov,项目名称:ocelot,代码行数:7,代码来源:beam.py
示例5: save_bessel_functions
def save_bessel_functions(N):
"""Generate N 2D shapelets and plot."""
beta2 = beta ** 2
B = empty((grid_size, grid_size)) # Don't want matrix behaviour here
# ---------------------------------------------------------------------------
# Basis function constants, and hermite polynomials
# ---------------------------------------------------------------------------
vals = [[n, 1.0 / sqrt((2 ** n) * sqrt(pi) * factorial(n, 1) * beta), 0, 0, 0] for n in xrange(N)]
expreal = exp(-theta.real ** 2 / (2 * beta2))
expimag = exp(-theta.imag ** 2 / (2 * beta2))
for n, K, H, _, _ in vals:
vals[n][3] = K * jn(n, theta.real) * expreal
vals[n][4] = K * jn(n, theta.imag) * expimag
pylab.figure()
l = 0
for v1 in vals:
for v2 in vals:
B = v1[3] * v2[4]
pylab.subplot(N, N, l + 1)
pylab.axis("off")
pylab.imshow(B.T)
l += 1
pylab.suptitle("Shapelets N=%i Beta=%.4f" % (N, beta))
# pylab.savefig("B%i.png" % N)
pylab.show()
开发者ID:jpcoles,项目名称:jcode,代码行数:29,代码来源:ml.py
示例6: model_two_basis_functions
def model_two_basis_functions():
""" A test function that returns a model similar to model(), except
that it uses the shapelet basis functions as the surface brightness
and does not normalize.
"""
data = empty((nepochs, grid_size, grid_size))
beta2 = beta ** 2
for t, z in star_track(nepochs):
if t == 0:
x = raytrace()
else:
x = raytrace(rE_true, z)
n = 0
K1 = 1.0 / sqrt(2 ** n * sqrt(pi) * factorial(n, 1) * beta)
H1 = hermite(n)
data[t] = (K1 * H1(x.real / beta) * exp(-x.real ** 2 / (2 * beta2))) * (
K1 * H1(x.imag / beta) * exp(-x.imag ** 2 / (2 * beta2))
)
# data[t] *= 100
# n = 1
# K1 = 1.0/sqrt(2**n * sqrt(pi) * factorial(n,1) * beta)
# H1 = hermite(n)
#
# data[t] += (K1 * H1(x.real/beta) * exp(-x.real**2/(2*beta2))) * \
# (K1 * H1(x.imag/beta) * exp(-x.imag**2/(2*beta2)))
return data
开发者ID:jpcoles,项目名称:jcode,代码行数:31,代码来源:ml.py
示例7: check_power_complex
def check_power_complex(self):
x = array([1 + 2j, 2 + 3j, 3 + 4j])
assert_equal(x ** 0, [1.0, 1.0, 1.0])
assert_equal(x ** 1, x)
assert_equal(x ** 2, [-3 + 4j, -5 + 12j, -7 + 24j])
assert_almost_equal(x ** (-1), [1 / (1 + 2j), 1 / (2 + 3j), 1 / (3 + 4j)])
assert_almost_equal(x ** (-3), [(-11 + 2j) / 125, (-46 - 9j) / 2197, (-117 - 44j) / 15625])
assert_almost_equal(x ** (0.5), [ncu.sqrt(1 + 2j), ncu.sqrt(2 + 3j), ncu.sqrt(3 + 4j)])
assert_almost_equal(x ** 14, [-76443 + 16124j, 23161315 + 58317492j, 5583548873 + 2465133864j])
开发者ID:dinarabdullin,项目名称:Pymol-script-repo,代码行数:9,代码来源:test_umath.py
示例8: test_power_float
def test_power_float(self):
x = np.array([1., 2., 3.])
assert_equal(x**0, [1., 1., 1.])
assert_equal(x**1, x)
assert_equal(x**2, [1., 4., 9.])
y = x.copy()
y **= 2
assert_equal(y, [1., 4., 9.])
assert_almost_equal(x**(-1), [1., 0.5, 1./3])
assert_almost_equal(x**(0.5), [1., ncu.sqrt(2), ncu.sqrt(3)])
开发者ID:8cH9azbsFifZ,项目名称:wspr,代码行数:10,代码来源:test_umath.py
示例9: test_power_float
def test_power_float(self):
x = np.array([1.0, 2.0, 3.0])
assert_equal(x ** 0, [1.0, 1.0, 1.0])
assert_equal(x ** 1, x)
assert_equal(x ** 2, [1.0, 4.0, 9.0])
y = x.copy()
y **= 2
assert_equal(y, [1.0, 4.0, 9.0])
assert_almost_equal(x ** (-1), [1.0, 0.5, 1.0 / 3])
assert_almost_equal(x ** (0.5), [1.0, ncu.sqrt(2), ncu.sqrt(3)])
开发者ID:jarrodmillman,项目名称:numpy,代码行数:10,代码来源:test_umath.py
示例10: _std
def _std(a, axis=None, dtype=None, out=None, ddof=0, keepdims=False):
ret = _var(a, axis=axis, dtype=dtype, out=out, ddof=ddof,
keepdims=keepdims)
if isinstance(ret, mu.ndarray):
ret = um.sqrt(ret, out=ret)
else:
ret = um.sqrt(ret)
return ret
开发者ID:MolecularFlipbook,项目名称:FlipbookApp,代码行数:10,代码来源:_methods.py
示例11: get_distance
def get_distance(locA, locB):
# use haversine forumla
print "ayyo"
earth_rad = 6371.0
dlat = deg2rad(locB[0] - locA[0])
dlon = deg2rad(locB[1] - locA[1])
a = sin(dlat / 2) * sin(dlat / 2) + \
cos(deg2rad(locA[0])) * cos(deg2rad(locB[0])) * \
sin(dlon / 2) * sin(dlon / 2)
c = 2 * arctan2(sqrt(a), sqrt(1 - a))
return earth_rad * c
开发者ID:dotslash,项目名称:Projects,代码行数:11,代码来源:dist_cities.py
示例12: get_envelope
def get_envelope(p_array, tws_i=Twiss()):
tws = Twiss()
p = p_array.p()
dx = tws_i.Dx*p
dy = tws_i.Dy*p
dpx = tws_i.Dxp*p
dpy = tws_i.Dyp*p
x = p_array.x() - dx
px = p_array.px() - dpx
y = p_array.y() - dy
py = p_array.py() - dpy
if ne_flag:
px = ne.evaluate('px * (1. - 0.5 * px * px - 0.5 * py * py)')
py = ne.evaluate('py * (1. - 0.5 * px * px - 0.5 * py * py)')
else:
px = px*(1.-0.5*px*px - 0.5*py*py)
py = py*(1.-0.5*px*px - 0.5*py*py)
tws.x = mean(x)
tws.y = mean(y)
tws.px =mean(px)
tws.py =mean(py)
if ne_flag:
tw_x = tws.x
tw_y = tws.y
tw_px = tws.px
tw_py = tws.py
tws.xx = mean(ne.evaluate('(x - tw_x) * (x - tw_x)'))
tws.xpx = mean(ne.evaluate('(x - tw_x) * (px - tw_px)'))
tws.pxpx =mean(ne.evaluate('(px - tw_px) * (px - tw_px)'))
tws.yy = mean(ne.evaluate('(y - tw_y) * (y - tw_y)'))
tws.ypy = mean(ne.evaluate('(y - tw_y) * (py - tw_py)'))
tws.pypy =mean(ne.evaluate('(py - tw_py) * (py - tw_py)'))
else:
tws.xx = mean((x - tws.x)*(x - tws.x))
tws.xpx = mean((x-tws.x)*(px-tws.px))
tws.pxpx = mean((px-tws.px)*(px-tws.px))
tws.yy = mean((y-tws.y)*(y-tws.y))
tws.ypy = mean((y-tws.y)*(py-tws.py))
tws.pypy = mean((py-tws.py)*(py-tws.py))
tws.p = mean( p_array.p())
tws.E = p_array.E
#tws.de = p_array.de
tws.emit_x = sqrt(tws.xx*tws.pxpx-tws.xpx**2)
tws.emit_y = sqrt(tws.yy*tws.pypy-tws.ypy**2)
#print tws.emit_x, sqrt(tws.xx*tws.pxpx-tws.xpx**2), tws.emit_y, sqrt(tws.yy*tws.pypy-tws.ypy**2)
tws.beta_x = tws.xx/tws.emit_x
tws.beta_y = tws.yy/tws.emit_y
tws.alpha_x = -tws.xpx/tws.emit_x
tws.alpha_y = -tws.ypy/tws.emit_y
return tws
开发者ID:iagapov,项目名称:ocelot,代码行数:53,代码来源:beam.py
示例13: sizes
def sizes(self):
if self.beta_x != 0:
self.gamma_x = (1. + self.alpha_x**2)/self.beta_x
else:
self.gamma_x = 0.
if self.beta_y != 0:
self.gamma_y = (1. + self.alpha_y**2)/self.beta_y
else:
self.gamma_y = 0.
self.sigma_x = sqrt((self.sigma_E/self.E*self.Dx)**2 + self.emit_x*self.beta_x)
self.sigma_y = sqrt((self.sigma_E/self.E*self.Dy)**2 + self.emit_y*self.beta_y)
self.sigma_xp = sqrt((self.sigma_E/self.E*self.Dxp)**2 + self.emit_x*self.gamma_x)
self.sigma_yp = sqrt((self.sigma_E/self.E*self.Dyp)**2 + self.emit_y*self.gamma_y)
开发者ID:iagapov,项目名称:ocelot,代码行数:15,代码来源:beam.py
示例14: rv_pqw
def rv_pqw(k, p, ecc, nu):
r"""Returns r and v vectors in perifocal frame.
.. math::
\vec{r} = \frac{h^2}{\mu}\frac{1}{1 + e\cos(\theta)}\begin{bmatrix}
\cos(\theta)\\
\sin(\theta)\\
0
\end{bmatrix} \\\\\\
\vec{v} = \frac{h^2}{\mu}\begin{bmatrix}
-\sin(\theta)\\
e+\cos(\theta)\\
0
\end{bmatrix}
Parameters
----------
k : float
Standard gravitational parameter (km^3 / s^2).
p : float
Semi-latus rectum or parameter (km).
ecc : float
Eccentricity.
nu: float
True anomaly (rad).
Returns
-------
r: ndarray
Position. Dimension 3 vector
v: ndarray
Velocity. Dimension 3 vector
Examples
--------
>>> from poliastro.constants import GM_earth
>>> k = GM_earth #Earth gravitational parameter
>>> ecc = 0.3 #Eccentricity
>>> h = 60000e6 #Angular momentum of the orbit [m^2]/[s]
>>> nu = np.deg2rad(120) #True Anomaly [rad]
>>> p = h**2 / k #Parameter of the orbit
>>> r, v = rv_pqw(k, p, ecc, nu)
>>> #Printing the results
r = [-5312706.25105345 9201877.15251336 0] [m]
v = [-5753.30180931 -1328.66813933 0] [m]/[s]
Note
----
These formulas can be checked at Curtis 3rd. Edition, page 110. Also the
example proposed is 2.11 of Curtis 3rd Edition book.
"""
r_pqw = (np.array([cos(nu), sin(nu), 0 * nu]) * p / (1 + ecc * cos(nu))).T
v_pqw = (np.array([-sin(nu), (ecc + cos(nu)), 0]) * sqrt(k / p)).T
return r_pqw, v_pqw
开发者ID:poliastro,项目名称:poliastro,代码行数:60,代码来源:elements.py
示例15: rv_pqw
def rv_pqw(k, p, ecc, nu):
"""Returns r and v vectors in perifocal frame.
"""
r_pqw = (np.array([cos(nu), sin(nu), 0 * nu]) * p / (1 + ecc * cos(nu))).T
v_pqw = (np.array([-sin(nu), (ecc + cos(nu)), 0]) * sqrt(k / p)).T
return r_pqw, v_pqw
开发者ID:aarribas,项目名称:poliastro,代码行数:7,代码来源:elements.py
示例16: kaiser
def kaiser(M,beta):
"""kaiser(M, beta) returns a Kaiser window of length M with shape parameter
beta.
"""
from numpy.dual import i0
n = arange(0,M)
alpha = (M-1)/2.0
return i0(beta * sqrt(1-((n-alpha)/alpha)**2.0))/i0(beta)
开发者ID:ruschecker,项目名称:DrugDiscovery-Home,代码行数:8,代码来源:function_base.py
示例17: corrcoef
def corrcoef(x, y=None, rowvar=1, bias=0):
"""The correlation coefficients
"""
c = cov(x, y, rowvar, bias)
try:
d = diag(c)
except ValueError: # scalar covariance
return 1
return c/sqrt(multiply.outer(d,d))
开发者ID:ruschecker,项目名称:DrugDiscovery-Home,代码行数:9,代码来源:function_base.py
示例18: fastGradientProjectionStream
def fastGradientProjectionStream(f, g, gradf, proxg, x0, initLip=None):
"""The (fast) proximal gradient method requires a gradient of f, and a prox
operator for g, supplied by gradf and proxg respectively."""
if initLip is None:
Lipk = 1.
else:
Lipk = initLip
eta = 2.
xko = x0
xk = x0
yk = x0
tk = 1
def F(x):
return f(x) + g(x)
Fxko = F(xko)
def Q(Lip, px, x):
d = (px - x).flatten() # treat all matrices as vectors
return f(x) + gradf(x).flatten().dot(d) + Lip * (norm(d) ** 2) / 2 + g(px)
def P(Lip, x):
return proxg(Lip, x - gradf(x) / Lip)
"""Non standard extension: expanding line search to find an initial estimate of Lipschitz constant"""
for k in range(5):
pyk = P(Lipk, yk)
if F(pyk) > Q(Lipk, pyk, yk):
break
yield pyk
Lipk = Lipk / (eta ** 4)
"""Start standard algorithm"""
while True:
yield xk
while True:
pyk = P(Lipk, yk)
Fyk = F(pyk)
if Fyk <= Q(Lipk, pyk, yk):
break
Lipk = Lipk * eta
zk = pyk
tkn = (1 + sqrt(1 + 4 * (tk ** 2))) / 2
if Fyk <= Fxko: # Fyk is F(zk)=F(pyk); Fxko is F(xko)
xk = zk
Fxk = Fyk
else:
xk = xko
Fxk = Fxko
yk = xk + (zk - xk) * tk / tkn + (xk - xko) * (tk - 1) / tkn
Fxko = Fxk
xko = xk
tk = tkn
开发者ID:daniel-vainsencher,项目名称:opti_streams,代码行数:57,代码来源:minimize.py
示例19: m_from_twiss
def m_from_twiss(Tw1, Tw2):
#% Transport matrix M for two sets of Twiss parameters (alpha,beta,psi)
b1 = Tw1[1]
a1 = Tw1[0]
psi1 = Tw1[2]
b2 = Tw2[1]
a2 = Tw2[0]
psi2 = Tw2[2]
psi = psi2-psi1
cosp = cos(psi)
sinp = sin(psi)
M = np.zeros((2, 2))
M[0, 0] = sqrt(b2/b1)*(cosp+a1*sinp)
M[0, 1] = sqrt(b2*b1)*sinp
M[1, 0] = ((a1-a2)*cosp-(1+a1*a2)*sinp)/sqrt(b2*b1)
M[1, 1] = sqrt(b1/b2)*(cosp-a2*sinp)
return M
开发者ID:iagapov,项目名称:ocelot,代码行数:18,代码来源:beam.py
示例20: ecef_to_lat_lon_alt1
def ecef_to_lat_lon_alt1(R, deg=True):
"""
Fukushima implementation of the Bowring algorithm (2006),
see [4] --
:param R: (X,Y,Z) -- coordinates in ECEF (numpy array)
:param deg: if True then lat and lon are returned in degrees (rad otherwise)
:return: (φ,θ,h) -- lat [deg], lon [deg], alt in WGS84 (numpy array)
"""
# WGS 84 constants
a = 6378137.0 # Equatorial Radius [m]
b = 6356752.314245 # Polar Radius [m]
e = 0.08181919092890624 # e = sqrt(1-b²/a²)
E = e ** 2
e1 = sqrt(1 - e ** 2) # e' = sqrt(1 - e²)
if isinstance(R, list): R = np.array(R)
p = sqrt(R[0] ** 2 + R[1] ** 2) # (1) - sqrt(X² + Y²)
az = abs(R[2])
Z = e1 * az / a
P = p / a
S, C = Z or 1, e1 * P or 1 # (C8) - zero approximation
max_iter = 5
for i in range(max_iter):
A = sqrt(S ** 2 + C ** 2)
Cn = P * A ** 3 - E * C ** 3
Sn = Z * A ** 3 + E * S ** 3
delta = abs(Sn / Cn - S / C) * C / S
if isnan(delta):
return ecef_to_lat_lon_alt1(R)
if abs(delta) < 1e-10 or i == max_iter - 1:
break
S, C = Sn, Cn
theta = np.math.atan2(R[1], R[0])
Cc = e1 * Cn
phi = np.sign(R[2]) * np.math.atan2(Sn, Cc)
h = (p * Cc + az * Sn - b * sqrt(Sn ** 2 + Cn ** 2)) / sqrt(Cc ** 2 + Sn ** 2)
if deg:
out = np.array([np.degrees(phi), np.degrees(theta), h])
else:
out = np.array([phi, theta, h])
# if filter(isnan, out):
# return ecef_to_lat_lon_alt1(R)
return out
开发者ID:kirienko,项目名称:pylgrim,代码行数:42,代码来源:ecef.py
注:本文中的numpy.core.umath.sqrt函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论