本文整理汇总了Python中numpy.conj方法的典型用法代码示例。如果您正苦于以下问题:Python numpy.conj方法的具体用法?Python numpy.conj怎么用?Python numpy.conj使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类numpy
的用法示例。
在下文中一共展示了numpy.conj方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_givens_inverse
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import conj [as 别名]
def test_givens_inverse():
r"""
The Givens rotation in OpenFermion is defined as
.. math::
\begin{pmatrix}
\cos(\theta) & -e^{i \varphi} \sin(\theta) \\
\sin(\theta) & e^{i \varphi} \cos(\theta)
\end{pmatrix}.
confirm numerically its hermitian conjugate is it's inverse
"""
a = numpy.random.random() + 1j * numpy.random.random()
b = numpy.random.random() + 1j * numpy.random.random()
ab_rotation = givens_matrix_elements(a, b, which='right')
assert numpy.allclose(ab_rotation.dot(numpy.conj(ab_rotation).T),
numpy.eye(2))
assert numpy.allclose(numpy.conj(ab_rotation).T.dot(ab_rotation),
numpy.eye(2))
示例2: test_circuit_generation_and_accuracy
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import conj [as 别名]
def test_circuit_generation_and_accuracy():
for dim in range(2, 10):
qubits = cirq.LineQubit.range(dim)
u_generator = numpy.random.random(
(dim, dim)) + 1j * numpy.random.random((dim, dim))
u_generator = u_generator - numpy.conj(u_generator).T
assert numpy.allclose(-1 * u_generator, numpy.conj(u_generator).T)
unitary = scipy.linalg.expm(u_generator)
circuit = cirq.Circuit()
circuit.append(optimal_givens_decomposition(qubits, unitary))
fermion_generator = QubitOperator(()) * 0.0
for i, j in product(range(dim), repeat=2):
fermion_generator += jordan_wigner(
FermionOperator(((i, 1), (j, 0)), u_generator[i, j]))
true_unitary = scipy.linalg.expm(
get_sparse_operator(fermion_generator).toarray())
assert numpy.allclose(true_unitary.conj().T.dot(true_unitary),
numpy.eye(2 ** dim, dtype=complex))
test_unitary = cirq.unitary(circuit)
assert numpy.isclose(
abs(numpy.trace(true_unitary.conj().T.dot(test_unitary))), 2 ** dim)
示例3: _gamma1_intermediates
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import conj [as 别名]
def _gamma1_intermediates(mp, t2=None):
# Memory optimization should be here
if t2 is None:
t2 = mp.t2
if t2 is None:
raise NotImplementedError("Run kmp2.kernel with `with_t2=True`")
nmo = mp.nmo
nocc = mp.nocc
nvir = nmo - nocc
nkpts = mp.nkpts
dtype = t2.dtype
dm1occ = np.zeros((nkpts, nocc, nocc), dtype=dtype)
dm1vir = np.zeros((nkpts, nvir, nvir), dtype=dtype)
for ki in range(nkpts):
for kj in range(nkpts):
for ka in range(nkpts):
kb = mp.khelper.kconserv[ki, ka, kj]
dm1vir[kb] += einsum('ijax,ijay->yx', t2[ki][kj][ka].conj(), t2[ki][kj][ka]) * 2 -\
einsum('ijax,ijya->yx', t2[ki][kj][ka].conj(), t2[ki][kj][kb])
dm1occ[kj] += einsum('ixab,iyab->xy', t2[ki][kj][ka].conj(), t2[ki][kj][ka]) * 2 -\
einsum('ixab,iyba->xy', t2[ki][kj][ka].conj(), t2[ki][kj][kb])
return -dm1occ, dm1vir
示例4: get_j
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import conj [as 别名]
def get_j(cell, dm, hermi=1, vhfopt=None, kpt=np.zeros(3), kpts_band=None):
dm = np.asarray(dm)
nao = dm.shape[-1]
coords = gen_grid.gen_uniform_grids(cell)
if kpts_band is None:
kpt1 = kpt2 = kpt
aoR_k1 = aoR_k2 = numint.eval_ao(cell, coords, kpt)
else:
kpt1 = kpts_band
kpt2 = kpt
aoR_k1 = numint.eval_ao(cell, coords, kpt1)
aoR_k2 = numint.eval_ao(cell, coords, kpt2)
ngrids, nao = aoR_k1.shape
def contract(dm):
vjR_k2 = get_vjR(cell, dm, aoR_k2)
vj = (cell.vol/ngrids) * np.dot(aoR_k1.T.conj(), vjR_k2.reshape(-1,1)*aoR_k1)
return vj
if dm.ndim == 2:
vj = contract(dm)
else:
vj = lib.asarray([contract(x) for x in dm.reshape(-1,nao,nao)])
return vj.reshape(dm.shape)
示例5: get_vkR
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import conj [as 别名]
def get_vkR(mf, cell, aoR_k1, aoR_k2, kpt1, kpt2):
'''Get the real-space 2-index "exchange" potential V_{i,k1; j,k2}(r)
where {i,k1} = exp^{i k1 r) |i> , {j,k2} = exp^{-i k2 r) <j|
'''
coords = gen_grid.gen_uniform_grids(cell)
ngrids, nao = aoR_k1.shape
expmikr = np.exp(-1j*np.dot(kpt1-kpt2,coords.T))
coulG = tools.get_coulG(cell, kpt1-kpt2, exx=True, mf=mf)
def prod(ij):
i, j = divmod(ij, nao)
rhoR = aoR_k1[:,i] * aoR_k2[:,j].conj()
rhoG = tools.fftk(rhoR, cell.mesh, expmikr)
vG = coulG*rhoG
vR = tools.ifftk(vG, cell.mesh, expmikr.conj())
return vR
if aoR_k1.dtype == np.double and aoR_k2.dtype == np.double:
vR = numpy.asarray([prod(ij).real for ij in range(nao**2)])
else:
vR = numpy.asarray([prod(ij) for ij in range(nao**2)])
return vR.reshape(nao,nao,-1).transpose(2,0,1)
示例6: __init__
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import conj [as 别名]
def __init__(self, j):
self._j = j
self._c2r = np.zeros( (2*j+1, 2*j+1), dtype=np.complex128)
self._c2r[j,j]=1.0
for m in range(1,j+1):
self._c2r[m+j, m+j] = sgn[m] * np.sqrt(0.5)
self._c2r[m+j,-m+j] = np.sqrt(0.5)
self._c2r[-m+j,-m+j]= 1j*np.sqrt(0.5)
self._c2r[-m+j, m+j]= -sgn[m] * 1j * np.sqrt(0.5)
self._hc_c2r = np.conj(self._c2r).transpose()
self._conj_c2r = np.conjugate(self._c2r) # what is the difference ? conj and conjugate
self._tr_c2r = np.transpose(self._c2r)
#print(abs(self._hc_c2r.conj().transpose()-self._c2r).sum())
#
#
#
示例7: get_k
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import conj [as 别名]
def get_k(self,dm):
"""
Update Exact Exchange Matrix
Args:
dm: float or complex
AO density matrix.
Returns:
kmat: float or complex
Exact Exchange in AO basis
"""
naux = self.auxmol.nao_nr()
nao = self.ks.mol.nao_nr()
kpj = np.einsum("ijp,jk->ikp", self.eri3c, dm)
pik = np.linalg.solve(self.eri2c, kpj.reshape(-1,naux).T.conj())
kmat = np.einsum("pik,kjp->ij", pik.reshape(naux,nao,nao), self.eri3c)
return kmat
示例8: unitary_to_process_mx
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import conj [as 别名]
def unitary_to_process_mx(U):
"""
Compute the super-operator which acts on (row)-vectorized
density matrices from a unitary operator (matrix) U which
acts on state vectors. This super-operator is given by
the tensor product of U and conjugate(U), i.e. kron(U,U.conj).
Parameters
----------
U : numpy array
The unitary matrix which acts on state vectors.
Returns
-------
numpy array
The super-operator process matrix.
"""
# U -> kron(U,Uc) since U rho U_dag -> kron(U,Uc)
# since AXB --row-vectorize--> kron(A,B.T)*vec(X)
return _np.kron(U, _np.conjugate(U))
示例9: svd_dotH
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import conj [as 别名]
def svd_dotH(self,s1,q1):
"""
Performs diagonal matrix multiplication conjugate
Implements :math:`q_0 = \\mathrm{diag}(s_1)^* q_1`.
:param s1: diagonal parameters
:param q1: input to the diagonal multiplication
:returns: :code:`q0` diagonal multiplication output
"""
srep = repeat_axes(np.conj(s1),self.sshape,self.srep_axes,rep=False)
q0 = srep*q1
return q0
#def __str__(self):
# string = str(self.name) + '\n'\
# + 'Input: ' + str(self.shape0) + ',' + str(self.dtype0)
# return string
示例10: azimuthal_symmetry
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import conj [as 别名]
def azimuthal_symmetry(X, Y, n, m):
p1 = 2
p2 = 1
p = np.sqrt(p1**2 + p2**2)
detX = np.real(X.hvhv*(X.hhhh*X.vvvv - X.hhvv*np.conj(X.hhvv)))
detY = np.real(Y.hvhv*(Y.hhhh*Y.vvvv - Y.hhvv*np.conj(Y.hhvv)))
detXY = np.real((X.hvhv+Y.hvhv) * ((X.hhhh+Y.hhhh)*(X.vvvv+Y.vvvv) - (X.hhvv+Y.hhvv)*(np.conj(X.hhvv)+np.conj(Y.hhvv))))
lnq = (p*(n+m)*np.log(n+m) - p*n*np.log(n) - p*m*np.log(m)
+ n*np.log(detX) + m*np.log(detY) - (n+m)*np.log(detXY))
rho1 = 1 - (2*p1**2 - 1)/(6*p1) * (1/n + 1/m - 1/(n+m))
rho2 = 1 - (2*p2**2 - 1)/(6*p2) * (1/n + 1/m - 1/(n+m))
rho = 1/p**2 * (p1**2 * rho1 + p2**2 * rho2)
w2 = - p**2/4 * (1-1/rho)**2 + (p1**2*(p1**2-1) + p2**2*(p2**2-1))/24 * (1/n**2 + 1/m**2 - 1/(n+m)**2) * 1/rho**2
return lnq, rho, w2
示例11: fexpand
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import conj [as 别名]
def fexpand(x, ns=1, axis=None):
"""
Reconstructs full spectrum from positive frequencies
Works on the last dimension (contiguous in c-stored array)
:param x: numpy.ndarray
:param axis: axis along which to perform reduction (last axis by default)
:return: numpy.ndarray
"""
if axis is None:
axis = x.ndim - 1
# dec = int(ns % 2) * 2 - 1
# xcomp = np.conj(np.flip(x[..., 1:x.shape[-1] + dec], axis=axis))
ilast = int((ns + (ns % 2)) / 2)
xcomp = np.conj(np.flip(np.take(x, np.arange(1, ilast), axis=axis), axis=axis))
return np.concatenate((x, xcomp), axis=axis)
示例12: _power_spectrum
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import conj [as 别名]
def _power_spectrum(daft, dim, N, density):
ps = (daft * np.conj(daft)).real
if density:
ps /= (np.asarray(N).prod()) ** 2
for i in dim:
ps /= daft['freq_' + i + '_spacing']
return ps
示例13: _cross_spectrum
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import conj [as 别名]
def _cross_spectrum(daft1, daft2, dim, N, density):
cs = (daft1 * np.conj(daft2)).real
if density:
cs /= (np.asarray(N).prod())**2
for i in dim:
cs /= daft1['freq_' + i + '_spacing']
return cs
示例14: test_power_spectrum
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import conj [as 别名]
def test_power_spectrum(self, dask):
"""Test the power spectrum function"""
N = 16
da = xr.DataArray(np.random.rand(2,N,N), dims=['time','y','x'],
coords={'time':np.array(['2019-04-18', '2019-04-19'],
dtype='datetime64'),
'y':range(N),'x':range(N)}
)
if dask:
da = da.chunk({'time': 1})
ps = xrft.power_spectrum(da, dim=['y','x'], window=True, density=False,
detrend='constant')
daft = xrft.dft(da, dim=['y','x'], detrend='constant', window=True)
npt.assert_almost_equal(ps.values, np.real(daft*np.conj(daft)))
npt.assert_almost_equal(np.ma.masked_invalid(ps).mask.sum(), 0.)
ps = xrft.power_spectrum(da, dim=['y'], real='x', window=True,
density=False, detrend='constant')
daft = xrft.dft(da, dim=['y'], real='x', detrend='constant', window=True)
npt.assert_almost_equal(ps.values, np.real(daft*np.conj(daft)))
### Normalized
ps = xrft.power_spectrum(da, dim=['y','x'], window=True, detrend='constant')
daft = xrft.dft(da, dim=['y','x'], window=True, detrend='constant')
test = np.real(daft*np.conj(daft))/N**4
dk = np.diff(np.fft.fftfreq(N, 1.))[0]
test /= dk**2
npt.assert_almost_equal(ps.values, test)
npt.assert_almost_equal(np.ma.masked_invalid(ps).mask.sum(), 0.)
### Remove least-square fit
ps = xrft.power_spectrum(da, dim=['y','x'],
window=True, density=False, detrend='linear'
)
daft = xrft.dft(da, dim=['y','x'], window=True, detrend='linear')
npt.assert_almost_equal(ps.values, np.real(daft*np.conj(daft)))
npt.assert_almost_equal(np.ma.masked_invalid(ps).mask.sum(), 0.)
示例15: test_cross_spectrum
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import conj [as 别名]
def test_cross_spectrum(self, dask):
"""Test the cross spectrum function"""
N = 16
dim = ['x','y']
da = xr.DataArray(np.random.rand(2,N,N), dims=['time','x','y'],
coords={'time':np.array(['2019-04-18', '2019-04-19'],
dtype='datetime64'),
'x':range(N), 'y':range(N)})
da2 = xr.DataArray(np.random.rand(2,N,N), dims=['time','x','y'],
coords={'time':np.array(['2019-04-18', '2019-04-19'],
dtype='datetime64'),
'x':range(N), 'y':range(N)})
if dask:
da = da.chunk({'time': 1})
da2 = da2.chunk({'time': 1})
daft = xrft.dft(da, dim=dim, shift=True, detrend='constant',
window=True)
daft2 = xrft.dft(da2, dim=dim, shift=True, detrend='constant',
window=True)
cs = xrft.cross_spectrum(da, da2, dim=dim, window=True, density=False,
detrend='constant')
npt.assert_almost_equal(cs.values, np.real(daft*np.conj(daft2)))
npt.assert_almost_equal(np.ma.masked_invalid(cs).mask.sum(), 0.)
cs = xrft.cross_spectrum(da, da2, dim=dim, shift=True, window=True,
detrend='constant')
test = (daft * np.conj(daft2)).real.values/N**4
dk = np.diff(np.fft.fftfreq(N, 1.))[0]
test /= dk**2
npt.assert_almost_equal(cs.values, test)
npt.assert_almost_equal(np.ma.masked_invalid(cs).mask.sum(), 0.)