本文整理汇总了Python中numpy.iscomplexobj方法的典型用法代码示例。如果您正苦于以下问题:Python numpy.iscomplexobj方法的具体用法?Python numpy.iscomplexobj怎么用?Python numpy.iscomplexobj使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类numpy
的用法示例。
在下文中一共展示了numpy.iscomplexobj方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: construct_tdm
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import iscomplexobj [as 别名]
def construct_tdm(self):
td_xy = 2 * numpy.asarray(self.td_xy)
tdm_oo = einsum('vxia,ipaq->vxpq', td_xy, self["oovo"])
tdm_ov = einsum('vxia,ipaq->vxpq', td_xy, self["oovv"])
tdm_vv = einsum('vxia,ipaq->vxpq', td_xy, self["ovvv"])
if numpy.iscomplexobj(self["oovv"]):
tdm_vo = einsum('vxia,ipaq->vxpq', td_xy, self["ovvo"])
else:
tdm_vo = tdm_ov.swapaxes(2, 3).conj()
tdm = numpy.concatenate(
(
numpy.concatenate((tdm_oo, tdm_ov), axis=3),
numpy.concatenate((tdm_vo, tdm_vv), axis=3)
),
axis=2,
)
return tdm
示例2: RCCSD
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import iscomplexobj [as 别名]
def RCCSD(mf, frozen=None, mo_coeff=None, mo_occ=None):
import numpy
from pyscf import lib
from pyscf.soscf import newton_ah
from pyscf.cc import dfccsd
if isinstance(mf, scf.uhf.UHF):
raise RuntimeError('RCCSD cannot be used with UHF method.')
elif isinstance(mf, scf.rohf.ROHF):
lib.logger.warn(mf, 'RCCSD method does not support ROHF method. ROHF object '
'is converted to UHF object and UCCSD method is called.')
mf = scf.addons.convert_to_uhf(mf)
return UCCSD(mf, frozen, mo_coeff, mo_occ)
if isinstance(mf, newton_ah._CIAH_SOSCF) or not isinstance(mf, scf.hf.RHF):
mf = scf.addons.convert_to_rhf(mf)
if getattr(mf, 'with_df', None):
return dfccsd.RCCSD(mf, frozen, mo_coeff, mo_occ)
elif numpy.iscomplexobj(mo_coeff) or numpy.iscomplexobj(mf.mo_coeff):
return rccsd.RCCSD(mf, frozen, mo_coeff, mo_occ)
else:
return ccsd.CCSD(mf, frozen, mo_coeff, mo_occ)
示例3: mkk2ab
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import iscomplexobj [as 别名]
def mkk2ab(mk, k):
"""
Transforms MK and M TD matrices into A and B matrices.
Args:
mk (numpy.ndarray): TD MK-matrix;
k (numpy.ndarray): TD K-matrix;
Returns:
A and B submatrices.
"""
if numpy.iscomplexobj(mk) or numpy.iscomplexobj(k):
raise ValueError("MK- and/or K-matrixes are complex-valued: no transform is possible")
m = solve(k.T, mk.T).T
a = 0.5 * (m + k)
b = 0.5 * (m - k)
return a, b
示例4: __init__
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import iscomplexobj [as 别名]
def __init__(self, mol, mf, mc, tol=None, freeze_orb=None):
self.tol = -1 if tol is None else tol
self.parameters = {}
self._mol = mol
self._nelec = (mc.nelecas[0] + mc.ncore, mc.nelecas[1] + mc.ncore)
self._copy_ci(mc)
if len(mc.mo_coeff.shape) == 3:
self.parameters["mo_coeff_alpha"] = mc.mo_coeff[0][:, : mc.ncas + mc.ncore]
self.parameters["mo_coeff_beta"] = mc.mo_coeff[1][:, : mc.ncas + mc.ncore]
else:
self.parameters["mo_coeff_alpha"] = mc.mo_coeff[:, : mc.ncas + mc.ncore]
self.parameters["mo_coeff_beta"] = mc.mo_coeff[:, : mc.ncas + mc.ncore]
self._coefflookup = ("mo_coeff_alpha", "mo_coeff_beta")
self.pbc_str = "PBC" if hasattr(mol, "a") else ""
self.iscomplex = bool(sum(map(np.iscomplexobj, self.parameters.values())))
self.get_phase = (lambda x: x / np.abs(x)) if self.iscomplex else np.sign
self.freeze_orb = [[], []] if freeze_orb is None else freeze_orb
示例5: _init_mol
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import iscomplexobj [as 别名]
def _init_mol(self, mol, mf):
from pyscf import scf
for s, lookup in enumerate(self._coefflookup):
if len(mf.mo_occ.shape) == 2:
self.parameters[lookup] = mf.mo_coeff[s][
:, np.asarray(mf.mo_occ[s] > 0.9)
]
else:
minocc = (0.9, 1.1)[s]
self.parameters[lookup] = mf.mo_coeff[:, np.asarray(mf.mo_occ > minocc)]
self._nelec = tuple(mol.nelec)
self._mol = mol
self.iscomplex = bool(sum(map(np.iscomplexobj, self.parameters.values())))
self.evaluate_orbitals = self._evaluate_orbitals_mol
self.evaluate_mos = self._evaluate_mos_mol
示例6: safe_bulk_eval_compact_polys
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import iscomplexobj [as 别名]
def safe_bulk_eval_compact_polys(vtape, ctape, paramvec, dest_shape):
"""Typechecking wrapper for :function:`bulk_eval_compact_polys`.
The underlying method has two implementations: one for real-valued
`ctape`, and one for complex-valued. This wrapper will dynamically
dispatch to the appropriate implementation method based on the
type of `ctape`. If the type of `ctape` is known prior to calling,
it's slightly faster to call the appropriate implementation method
directly; if not.
"""
if _np.iscomplexobj(ctape):
ret = bulk_eval_compact_polys_complex(vtape, ctape, paramvec, dest_shape)
im_norm = _np.linalg.norm(_np.imag(ret))
if im_norm > 1e-6:
print("WARNING: norm(Im part) = {:g}".format(im_norm))
else:
ret = bulk_eval_compact_polys(vtape, ctape, paramvec, dest_shape)
return _np.real(ret)
示例7: __init__
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import iscomplexobj [as 别名]
def __init__(self, vec, evotype="auto", typ="prep"):
"""
Initialize a FullSPAMVec object.
Parameters
----------
vec : array_like or SPAMVec
a 1D numpy array representing the SPAM operation. The
shape of this array sets the dimension of the SPAM op.
evotype : {"densitymx", "statevec"}
the evolution type being used.
typ : {"prep", "effect"}
whether this is a state preparation or an effect (measurement)
SPAM vector.
"""
vec = SPAMVec.convert_to_vector(vec)
if evotype == "auto":
evotype = "statevec" if _np.iscomplexobj(vec) else "densitymx"
assert(evotype in ("statevec", "densitymx")), \
"Invalid evolution type '%s' for %s" % (evotype, self.__class__.__name__)
DenseSPAMVec.__init__(self, vec, evotype, typ)
示例8: test_poly
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import iscomplexobj [as 别名]
def test_poly(self):
assert_array_almost_equal(np.poly([3, -np.sqrt(2), np.sqrt(2)]),
[1, -3, -2, 6])
# From matlab docs
A = [[1, 2, 3], [4, 5, 6], [7, 8, 0]]
assert_array_almost_equal(np.poly(A), [1, -6, -72, -27])
# Should produce real output for perfect conjugates
assert_(np.isrealobj(np.poly([+1.082j, +2.613j, -2.613j, -1.082j])))
assert_(np.isrealobj(np.poly([0+1j, -0+-1j, 1+2j,
1-2j, 1.+3.5j, 1-3.5j])))
assert_(np.isrealobj(np.poly([1j, -1j, 1+2j, 1-2j, 1+3j, 1-3.j])))
assert_(np.isrealobj(np.poly([1j, -1j, 1+2j, 1-2j])))
assert_(np.isrealobj(np.poly([1j, -1j, 2j, -2j])))
assert_(np.isrealobj(np.poly([1j, -1j])))
assert_(np.isrealobj(np.poly([1, -1])))
assert_(np.iscomplexobj(np.poly([1j, -1.0000001j])))
np.random.seed(42)
a = np.random.randn(100) + 1j*np.random.randn(100)
assert_(np.isrealobj(np.poly(np.concatenate((a, np.conjugate(a))))))
示例9: _maybe_null_out
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import iscomplexobj [as 别名]
def _maybe_null_out(result, axis, mask, min_count=1):
if axis is not None and getattr(result, 'ndim', False):
null_mask = (mask.shape[axis] - mask.sum(axis) - min_count) < 0
if np.any(null_mask):
if is_numeric_dtype(result):
if np.iscomplexobj(result):
result = result.astype('c16')
else:
result = result.astype('f8')
result[null_mask] = np.nan
else:
# GH12941, use None to auto cast null
result[null_mask] = None
elif result is not tslibs.NaT:
null_mask = mask.size - mask.sum()
if null_mask < min_count:
result = np.nan
return result
示例10: __init__
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import iscomplexobj [as 别名]
def __init__(self, diag, dims=None, dir=0, dtype='float64'):
self.diag = diag.flatten()
self.complex = True if np.iscomplexobj(self.diag) else False
if dims is None:
self.shape = (len(self.diag), len(self.diag))
self.dims = None
self.reshape = False
else:
diagdims = [1] * len(dims)
diagdims[dir] = dims[dir]
self.diag = self.diag.reshape(diagdims)
self.shape = (np.prod(dims), np.prod(dims))
self.dims = dims
self.reshape = True
self.dtype = np.dtype(dtype)
self.explicit = False
示例11: __init__
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import iscomplexobj [as 别名]
def __init__(self, A, dims=None, dtype='float64'):
self.A = A
if isinstance(A, np.ndarray):
self.complex = np.iscomplexobj(A)
else:
self.complex = np.iscomplexobj(A.data)
if dims is None:
self.reshape = False
self.shape = A.shape
self.explicit = True
else:
if isinstance(dims, int):
dims = (dims, )
self.reshape = True
self.dims = np.array(dims, dtype=np.int)
self.shape = (A.shape[0]*np.prod(self.dims),
A.shape[1]*np.prod(self.dims))
self.explicit = False
self.dtype = np.dtype(dtype)
示例12: _augmented_orthonormal_cols
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import iscomplexobj [as 别名]
def _augmented_orthonormal_cols(x, k):
# extract the shape of the x array
n, m = x.shape
# create the expanded array and copy x into it
y = np.empty((n, m+k), dtype=x.dtype)
y[:, :m] = x
# do some modified gram schmidt to add k random orthonormal vectors
for i in range(k):
# sample a random initial vector
v = np.random.randn(n)
if np.iscomplexobj(x):
v = v + 1j*np.random.randn(n)
# subtract projections onto the existing unit length vectors
for j in range(m+i):
u = y[:, j]
v -= (np.dot(v, u.conj()) / np.dot(u, u.conj())) * u
# normalize v
v /= np.sqrt(np.dot(v, v.conj()))
# add v into the output array
y[:, m+i] = v
# return the expanded array
return y
示例13: _correlate_or_convolve
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import iscomplexobj [as 别名]
def _correlate_or_convolve(input, weights, output, mode, cval, origin,
convolution):
input = numpy.asarray(input)
if numpy.iscomplexobj(input):
raise TypeError('Complex type not supported')
origins = _ni_support._normalize_sequence(origin, input.ndim)
weights = numpy.asarray(weights, dtype=numpy.float64)
wshape = [ii for ii in weights.shape if ii > 0]
if len(wshape) != input.ndim:
raise RuntimeError('filter weights array has incorrect shape.')
if convolution:
weights = weights[tuple([slice(None, None, -1)] * weights.ndim)]
for ii in range(len(origins)):
origins[ii] = -origins[ii]
if not weights.shape[ii] & 1:
origins[ii] -= 1
for origin, lenw in zip(origins, wshape):
if (lenw // 2 + origin < 0) or (lenw // 2 + origin > lenw):
raise ValueError('invalid origin')
if not weights.flags.contiguous:
weights = weights.copy()
output, return_value = _ni_support._get_output(output, input)
mode = _ni_support._extend_mode_to_code(mode)
_nd_image.correlate(input, weights, output, mode, cval, origins)
return return_value
示例14: _maybe_null_out
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import iscomplexobj [as 别名]
def _maybe_null_out(result, axis, mask, min_count=1):
if axis is not None and getattr(result, 'ndim', False):
null_mask = (mask.shape[axis] - mask.sum(axis) - min_count) < 0
if np.any(null_mask):
if is_numeric_dtype(result):
if np.iscomplexobj(result):
result = result.astype('c16')
else:
result = result.astype('f8')
result[null_mask] = np.nan
else:
# GH12941, use None to auto cast null
result[null_mask] = None
elif result is not tslib.NaT:
null_mask = mask.size - mask.sum()
if null_mask < min_count:
result = np.nan
return result
示例15: stft_data
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import iscomplexobj [as 别名]
def stft_data(self, value):
if value is None:
self._stft_data = None
return
elif not isinstance(value, np.ndarray):
raise AudioSignalException('Type of self.stft_data must be of type np.ndarray!')
if value.ndim == 1:
raise AudioSignalException('Cannot support arrays with less than 2 dimensions!')
if value.ndim == 2:
value = np.expand_dims(value, axis=constants.STFT_CHAN_INDEX)
if value.ndim > 3:
raise AudioSignalException('Cannot support arrays with more than 3 dimensions!')
if not np.iscomplexobj(value):
warnings.warn('Initializing STFT with data that is non-complex. '
'This might lead to weird results!')
self._stft_data = value