本文整理匯總了Python中numpy.sinh方法的典型用法代碼示例。如果您正苦於以下問題:Python numpy.sinh方法的具體用法?Python numpy.sinh怎麽用?Python numpy.sinh使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類numpy
的用法示例。
在下文中一共展示了numpy.sinh方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: psi2c2c3
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import sinh [as 別名]
def psi2c2c3(self, psi0):
c2 = np.zeros(len(psi0))
c3 = np.zeros(len(psi0))
psi12 = np.sqrt(np.abs(psi0))
pos = psi0 >= 0
neg = psi0 < 0
if np.any(pos):
c2[pos] = (1 - np.cos(psi12[pos]))/psi0[pos]
c3[pos] = (psi12[pos] - np.sin(psi12[pos]))/psi12[pos]**3.
if any(neg):
c2[neg] = (1 - np.cosh(psi12[neg]))/psi0[neg]
c3[neg] = (np.sinh(psi12[neg]) - psi12[neg])/psi12[neg]**3.
tmp = c2+c3 == 0
if any(tmp):
c2[tmp] = 1./2.
c3[tmp] = 1./6.
return c2,c3
示例2: __init__
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import sinh [as 別名]
def __init__(self, img, percentiles=[1, 99]):
"""Create norm that is linear between lower and upper percentile of img
Parameters
----------
img: array_like
Image to normalize
percentile: array_like, default=[1,99]
Lower and upper percentile to consider. Pixel values below will be
set to zero, above to saturated.
"""
assert len(percentiles) == 2
vmin, vmax = np.percentile(img, percentiles)
# solution for beta assumes flat spectrum at vmax
stretch = vmax - vmin
beta = stretch / np.sinh(1)
super().__init__(minimum=vmin, stretch=stretch, Q=beta)
示例3: c2c3
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import sinh [as 別名]
def c2c3(psi): # Stumpff functions definitions
c2, c3 = 0, 0
if np.any(psi > 1e-6):
c2 = (1 - np.cos(np.sqrt(psi))) / psi
c3 = (np.sqrt(psi) - np.sin(np.sqrt(psi))) / np.sqrt(psi ** 3)
if np.any(psi < -1e-6):
c2 = (1 - np.cosh(np.sqrt(-psi))) / psi
c3 = (np.sinh(np.sqrt(-psi)) - np.sqrt(-psi)) / np.sqrt(-psi ** 3)
if np.any(abs(psi) <= 1e-6):
c2 = 0.5
c3 = 1. / 6.
return c2, c3
示例4: tauStep
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import sinh [as 別名]
def tauStep(dtau, v0, x0, t0, g):
## linear step in proper time of clock.
## If an object has proper acceleration g and starts at position x0 with speed v0 at time t0
## as seen from an inertial frame, then return the new v, x, t after proper time dtau has elapsed.
## Compute how much t will change given a proper-time step of dtau
gamma = (1. - v0**2)**-0.5
if g == 0:
dt = dtau * gamma
else:
v0g = v0 * gamma
dt = (np.sinh(dtau * g + np.arcsinh(v0g)) - v0g) / g
#return v0 + dtau * g, x0 + v0*dt, t0 + dt
v1, x1, t1 = Simulation.hypTStep(dt, v0, x0, t0, g)
return v1, x1, t0+dt
示例5: _eq_10_42
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import sinh [as 別名]
def _eq_10_42(lam_1, lam_2, t_12):
"""
Equation (10.42) of Functions of Matrices: Theory and Computation.
Notes
-----
This is a helper function for _fragment_2_1 of expm_2009.
Equation (10.42) is on page 251 in the section on Schur algorithms.
In particular, section 10.4.3 explains the Schur-Parlett algorithm.
expm([[lam_1, t_12], [0, lam_1])
=
[[exp(lam_1), t_12*exp((lam_1 + lam_2)/2)*sinch((lam_1 - lam_2)/2)],
[0, exp(lam_2)]
"""
# The plain formula t_12 * (exp(lam_2) - exp(lam_2)) / (lam_2 - lam_1)
# apparently suffers from cancellation, according to Higham's textbook.
# A nice implementation of sinch, defined as sinh(x)/x,
# will apparently work around the cancellation.
a = 0.5 * (lam_1 + lam_2)
b = 0.5 * (lam_1 - lam_2)
return t_12 * np.exp(a) * _sinch(b)
示例6: fields
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import sinh [as 別名]
def fields(x,y,z, kx, ky, kz, B0):
k1 = -B0*kx/ky
k2 = -B0*kz/ky
kx_x = kx*x
ky_y = ky*y
kz_z = kz*z
cosx = np.cos(kx_x)
sinhy = np.sinh(ky_y)
cosz = np.cos(kz_z)
Bx = k1*np.sin(kx_x)*sinhy*cosz #// here kx is only real
By = B0*cosx*np.cosh(ky_y)*cosz
Bz = k2*cosx*sinhy*np.sin(kz_z)
#Bx = ne.evaluate("k1*sin(kx*x)*sinhy*cosz")
#By = ne.evaluate("B0*cosx*cosh(ky*y)*cosz")
#Bz = ne.evaluate("k2*cosx*sinhy*sin(kz*z)")
return Bx, By, Bz
示例7: TMS
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import sinh [as 別名]
def TMS(r, phi):
"""Two-mode squeezing.
Args:
r (float): squeezing magnitude
phi (float): rotation parameter
Returns:
array: symplectic transformation matrix
"""
cp = np.cos(phi)
sp = np.sin(phi)
ch = np.cosh(r)
sh = np.sinh(r)
S = np.array(
[
[ch, cp * sh, 0, sp * sh],
[cp * sh, ch, sp * sh, 0],
[0, sp * sh, ch, -cp * sh],
[sp * sh, 0, -cp * sh, ch],
]
)
return S
示例8: test_squeezed_state_gaussian
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import sinh [as 別名]
def test_squeezed_state_gaussian(self, r, phi, hbar, tol):
"""test squeezed state returns correct means and covariance"""
means, cov = utils.squeezed_state(r, phi, basis="gaussian", hbar=hbar)
cov_expected = (hbar / 2) * np.array(
[
[
np.cosh(2 * r) - np.cos(phi) * np.sinh(2 * r),
-2 * np.cosh(r) * np.sin(phi) * np.sinh(r),
],
[
-2 * np.cosh(r) * np.sin(phi) * np.sinh(r),
np.cosh(2 * r) + np.cos(phi) * np.sinh(2 * r),
],
]
)
assert np.all(means == np.zeros([2]))
assert np.allclose(cov, cov_expected, atol=tol, rtol=0)
示例9: test_displaced_squeezed_state_gaussian
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import sinh [as 別名]
def test_displaced_squeezed_state_gaussian(self, r_d, phi_d, r_s, phi_s, hbar, tol):
"""test displaced squeezed state returns correct means and covariance"""
means, cov = utils.displaced_squeezed_state(r_d, phi_d, r_s, phi_s, basis="gaussian", hbar=hbar)
a = r_d * np.exp(1j * phi_d)
means_expected = np.array([[a.real, a.imag]]) * np.sqrt(2 * hbar)
cov_expected = (hbar / 2) * np.array(
[
[
np.cosh(2 * r_s) - np.cos(phi_s) * np.sinh(2 * r_s),
-2 * np.cosh(r_s) * np.sin(phi_s) * np.sinh(r_s),
],
[
-2 * np.cosh(r_s) * np.sin(phi_s) * np.sinh(r_s),
np.cosh(2 * r_s) + np.cos(phi_s) * np.sinh(2 * r_s),
],
]
)
assert np.allclose(means, means_expected, atol=tol, rtol=0)
assert np.allclose(cov, cov_expected, atol=tol, rtol=0)
示例10: test_displaced_squeezed_state_fock
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import sinh [as 別名]
def test_displaced_squeezed_state_fock(self, r_d, phi_d, r_s, phi_s, hbar, cutoff, tol):
"""test displaced squeezed state returns correct Fock basis state vector"""
state = utils.displaced_squeezed_state(r_d, phi_d, r_s, phi_s, basis="fock", fock_dim=cutoff, hbar=hbar)
a = r_d * np.exp(1j * phi_d)
if r_s == 0:
pytest.skip("test only non-zero squeezing")
n = np.arange(cutoff)
gamma = a * np.cosh(r_s) + np.conj(a) * np.exp(1j * phi_s) * np.sinh(r_s)
coeff = np.diag(
(0.5 * np.exp(1j * phi_s) * np.tanh(r_s)) ** (n / 2) / np.sqrt(fac(n) * np.cosh(r_s))
)
expected = H(gamma / np.sqrt(np.exp(1j * phi_s) * np.sinh(2 * r_s)), coeff)
expected *= np.exp(
-0.5 * np.abs(a) ** 2 - 0.5 * np.conj(a) ** 2 * np.exp(1j * phi_s) * np.tanh(r_s)
)
assert np.allclose(state, expected, atol=tol, rtol=0)
示例11: matrix_elem
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import sinh [as 別名]
def matrix_elem(n, r, m):
"""Matrix element corresponding to squeezed density matrix[n, m]"""
eps = 1e-10
if n % 2 != m % 2:
return 0.0
if r == 0.0:
return np.complex(n == m) # delta function
k = np.arange(m % 2, min([m, n]) + 1, 2)
res = np.sum(
(-1) ** ((n - k) / 2)
* np.exp(
(lg(m + 1) + lg(n + 1)) / 2
- lg(k + 1)
- lg((m - k) / 2 + 1)
- lg((n - k) / 2 + 1)
)
* (np.sinh(r) / 2 + eps) ** ((n + m - 2 * k) / 2)
/ (np.cosh(r) ** ((n + m + 1) / 2))
)
return res
示例12: test_squeezed_coherent
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import sinh [as 別名]
def test_squeezed_coherent(setup_backend, hbar, tol):
"""Test Wigner function for a squeezed coherent state
matches the analytic result"""
backend = setup_backend(1)
backend.prepare_coherent_state(np.abs(A), np.angle(A), 0)
backend.squeeze(R, PHI, 0)
state = backend.state()
W = state.wigner(0, XVEC, XVEC)
rot = rotm(PHI / 2)
# exact wigner function
alpha = A * np.cosh(R) - np.conjugate(A) * np.exp(1j * PHI) * np.sinh(R)
mu = np.array([alpha.real, alpha.imag]) * np.sqrt(2 * hbar)
cov = np.diag([np.exp(-2 * R), np.exp(2 * R)])
cov = np.dot(rot, np.dot(cov, rot.T)) * hbar / 2.0
Wexact = wigner(GRID, mu, cov)
assert np.allclose(W, Wexact, atol=0.01, rtol=0)
示例13: test_squeezed_coherent
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import sinh [as 別名]
def test_squeezed_coherent(self, setup_backend, hbar, batch_size, tol):
"""Test squeezed coherent state has correct mean and variance"""
# quadrature rotation angle
backend = setup_backend(1)
qphi = 0.78
backend.prepare_displaced_squeezed_state(np.abs(a), np.angle(a), r, phi, 0)
state = backend.state()
res = np.array(state.quad_expectation(0, phi=qphi)).T
xphi_mean = (a.real * np.cos(qphi) + a.imag * np.sin(qphi)) * np.sqrt(2 * hbar)
xphi_var = (np.cosh(2 * r) - np.cos(phi - 2 * qphi) * np.sinh(2 * r)) * hbar / 2
res_exact = np.array([xphi_mean, xphi_var])
if batch_size is not None:
res_exact = np.tile(res_exact, batch_size)
assert np.allclose(res.flatten(), res_exact.flatten(), atol=tol, rtol=0)
示例14: test_number_expectation_two_mode_squeezed
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import sinh [as 別名]
def test_number_expectation_two_mode_squeezed(self, setup_backend, tol, batch_size):
"""Tests the expectation value of photon numbers when there is correlation"""
if batch_size is not None:
pytest.skip("Does not support batch mode")
backend = setup_backend(3)
state = backend.state()
r = 0.2
phi = 0.0
backend.prepare_squeezed_state(r, phi, 0)
backend.prepare_squeezed_state(-r, phi, 2)
backend.beamsplitter(np.pi/4, np.pi, 0, 2)
state = backend.state()
nbar = np.sinh(r) ** 2
res = state.number_expectation([2, 0])
assert np.allclose(res[0], 2 * nbar ** 2 + nbar, atol=tol, rtol=0)
res = state.number_expectation([0])
assert np.allclose(res[0], nbar, atol=tol, rtol=0)
res = state.number_expectation([2])
assert np.allclose(res[0], nbar, atol=tol, rtol=0)
示例15: cheb2ap
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import sinh [as 別名]
def cheb2ap(N, rs):
"""Return (z,p,k) zero, pole, gain for Nth order Chebyshev type II lowpass
analog filter prototype with `rs` decibels of ripple in the stopband.
The filter's angular (e.g. rad/s) cutoff frequency is normalized to 1,
defined as the point at which the gain first reaches -`rs`.
"""
de = 1.0 / sqrt(10 ** (0.1 * rs) - 1)
mu = arcsinh(1.0 / de) / N
if N % 2:
n = numpy.concatenate((numpy.arange(1, N - 1, 2),
numpy.arange(N + 2, 2 * N, 2)))
else:
n = numpy.arange(1, 2 * N, 2)
z = conjugate(1j / cos(n * pi / (2.0 * N)))
p = exp(1j * (pi * numpy.arange(1, 2 * N, 2) / (2.0 * N) + pi / 2.0))
p = sinh(mu) * p.real + 1j * cosh(mu) * p.imag
p = 1.0 / p
k = (numpy.prod(-p, axis=0) / numpy.prod(-z, axis=0)).real
return z, p, k