本文整理匯總了Python中numpy.isrealobj方法的典型用法代碼示例。如果您正苦於以下問題:Python numpy.isrealobj方法的具體用法?Python numpy.isrealobj怎麽用?Python numpy.isrealobj使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類numpy
的用法示例。
在下文中一共展示了numpy.isrealobj方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_poly
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import isrealobj [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))))))
示例2: atal
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import isrealobj [as 別名]
def atal(x, order, num_coefs):
x = np.atleast_1d(x)
n = x.size
if x.ndim > 1:
raise ValueError("Only rank 1 input supported for now.")
if not np.isrealobj(x):
raise ValueError("Only real input supported for now.")
a, e, kk = lpc(x, order)
c = np.zeros(num_coefs)
c[0] = a[0]
for m in range(1, order+1):
c[m] = - a[m]
for k in range(1, m):
c[m] += (float(k)/float(m)-1)*a[k]*c[m-k]
for m in range(order+1, num_coefs):
for k in range(1, order+1):
c[m] += (float(k)/float(m)-1)*a[k]*c[m-k]
return c
示例3: predict
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import isrealobj [as 別名]
def predict(self, x):
"""
Args:
x: Shape (N, D)
Returns: Affiliation with shape (K, N)
"""
N, D = x.shape
assert np.isrealobj(x), x.dtype
labels = self.kmeans.predict(x)
affiliations = labels_to_one_hot(
labels, self.kmeans.n_clusters, axis=-2, keepdims=False,
dtype=x.dtype
)
assert affiliations.shape == (self.kmeans.n_clusters, N)
return affiliations
示例4: fit
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import isrealobj [as 別名]
def fit(self, y, saliency=None, covariance_type="full"):
"""
Args:
y: Shape (..., N, D)
saliency: Importance weighting for each observation, shape (..., N)
covariance_type: Either 'full', 'diagonal', or 'spherical'
Returns:
"""
assert np.isrealobj(y), y.dtype
if saliency is not None:
assert is_broadcast_compatible(y.shape[:-1], saliency.shape), (
y.shape, saliency.shape
)
return self._fit(y, saliency=saliency, covariance_type=covariance_type)
示例5: predict
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import isrealobj [as 別名]
def predict(self, observation, embedding):
"""
Args:
observation: Shape (F, T, D)
embedding: Shape (F, T, E)
Returns:
affiliation: Shape (F, K, T)
"""
assert np.iscomplexobj(observation), observation.dtype
assert np.isrealobj(embedding), embedding.dtype
observation = observation / np.maximum(
np.linalg.norm(observation, axis=-1, keepdims=True),
np.finfo(observation.dtype).tiny,
)
affiliation, quadratic_form = self._predict(observation, embedding)
return affiliation
示例6: inverse
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import isrealobj [as 別名]
def inverse(self, encoded, duration=None):
'''Inverse static tag transformation'''
ann = jams.Annotation(namespace=self.namespace, duration=duration)
if np.isrealobj(encoded):
detected = (encoded >= 0.5)
else:
detected = encoded
for vd in self.encoder.inverse_transform(np.atleast_2d(detected))[0]:
vid = np.flatnonzero(self.encoder.transform(np.atleast_2d(vd)))
ann.append(time=0,
duration=duration,
value=vd,
confidence=encoded[vid])
return ann
示例7: polyval
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import isrealobj [as 別名]
def polyval(self, chebcoeff):
"""
Compute the interpolation values at Chebyshev points.
chebcoeff: Chebyshev coefficients
"""
N = len(chebcoeff)
if N == 1:
return chebcoeff
data = even_data(chebcoeff)/2
data[0] *= 2
data[N-1] *= 2
fftdata = 2*(N-1)*fftpack.ifft(data, axis=0)
complex_values = fftdata[:N]
# convert to real if input was real
if np.isrealobj(chebcoeff):
values = np.real(complex_values)
else:
values = complex_values
return values
示例8: dct
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import isrealobj [as 別名]
def dct(data):
"""
Compute DCT using FFT
"""
N = len(data)//2
fftdata = fftpack.fft(data, axis=0)[:N+1]
fftdata /= N
fftdata[0] /= 2.
fftdata[-1] /= 2.
if np.isrealobj(data):
data = np.real(fftdata)
else:
data = fftdata
return data
# ----------------------------------------------------------------
# Add overloaded operators
# ----------------------------------------------------------------
示例9: correlate_periodic
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import isrealobj [as 別名]
def correlate_periodic(a, v=None):
"""Cross-correlation of two 1-dimensional periodic sequences.
a and v must be sequences with the same length. If v is not specified, it is
assumed to be the same as a (i.e. the function computes auto-correlation).
:param a: input sequence #1
:param v: input sequence #2
:returns: discrete periodic cross-correlation of a and v
"""
a_fft = _np.fft.fft(_np.asarray(a))
if v is None:
v_cfft = a_fft.conj()
else:
v_cfft = _np.fft.fft(_np.asarray(v)).conj()
x = _np.fft.ifft(a_fft * v_cfft)
if _np.isrealobj(a) and (v is None or _np.isrealobj(v)):
x = x.real
return x
示例10: rc2is
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import isrealobj [as 別名]
def rc2is(k):
"""Convert reflection coefficients to inverse sine parameters.
:param k: reflection coefficients
:return: inverse sine parameters
.. seealso:: :func:`is2rc`, :func:`rc2poly`, :func:`rc2acC`, :func:`rc2lar`.
Reference: J.R. Deller, J.G. Proakis, J.H.L. Hansen, "Discrete-Time
Processing of Speech Signals", Prentice Hall, Section 7.4.5.
"""
assert numpy.isrealobj(k), 'Inverse sine parameters not defined for complex reflection coefficients.'
if max(numpy.abs(k)) >= 1:
raise ValueError('All reflection coefficients should have magnitude less than unity.')
return (2/numpy.pi)*numpy.arcsin(k)
示例11: rc2lar
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import isrealobj [as 別名]
def rc2lar(k):
"""Convert reflection coefficients to log area ratios.
:param k: reflection coefficients
:return: inverse sine parameters
The log area ratio is defined by G = log((1+k)/(1-k)) , where the K
parameter is the reflection coefficient.
.. seealso:: :func:`lar2rc`, :func:`rc2poly`, :func:`rc2ac`, :func:`rc2ic`.
:References:
[1] J. Makhoul, "Linear Prediction: A Tutorial Review," Proc. IEEE, Vol.63, No.4, pp.561-580, Apr 1975.
"""
assert numpy.isrealobj(k), 'Log area ratios not defined for complex reflection coefficients.'
if max(numpy.abs(k)) >= 1:
raise ValueError('All reflection coefficients should have magnitude less than unity.')
# Use the relation, atanh(x) = (1/2)*log((1+k)/(1-k))
return -2 * numpy.arctanh(-numpy.array(k))
示例12: grad
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import isrealobj [as 別名]
def grad(self, input_vals: List[np.ndarray],
grad_val: np.ndarray) -> List[np.ndarray]:
"""Computes gradient via a adjoint calculation.
Args:
input_vals: List of the input values.
grad_val: Gradient of the output.
Returns:
Gradient.
"""
omega = 2 * np.pi / self._wlen
efields = self._simulate(input_vals[0])
B = omega**2 * scipy.sparse.diags(efields, 0)
d = self._simulate_adjoint(input_vals[0],
np.conj(grad_val) / (-1j * omega))
total_df_dz = np.conj(np.transpose(d)) @ B
# If this is a function that maps from real to complex, we have to
# to take the real part to make gradient real.
if np.isrealobj(input_vals[0]):
total_df_dz = np.real(total_df_dz)
return [total_df_dz]
示例13: _shift_grid_by_linear
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import isrealobj [as 別名]
def _shift_grid_by_linear(self, dx):
axes = sorted(dx.keys())
shift = np.zeros(len(self.axes))
for i, d in dx.items():
shift[i] = d
shift_px = shift/self.spacing
ret = copy.copy(self)
if np.isrealobj(self.matrix):
ret.matrix = spnd.shift(self.matrix, -shift_px, order=1, mode='nearest')
else:
real, imag = self.matrix.real.copy(), self.matrix.imag.copy()
ret.matrix = np.empty_like(matrix)
spnd.shift(real, -shift_px, output=ret.matrix.real, order=1, mode='nearest')
spnd.shift(imag, -shift_px, output=ret.matrix.imag, order=1, mode='nearest')
for i in axes:
ret.axes[i] = Axis(grid_node=self.axes[i].grid_node + dx[i],
grid=self.axes[i].grid + dx[i])
return ret
示例14: _fftconv
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import isrealobj [as 別名]
def _fftconv(a, b, axes=(0, 1)):
"""Patched version of :func:`sporco.fft.fftconv`."""
if cp.isrealobj(a) and cp.isrealobj(b):
fft = cp.fft.rfftn
ifft = cp.fft.irfftn
else:
fft = cp.fft.fftn
ifft = cp.fft.ifftn
dims = cp.maximum(cp.asarray([a.shape[i] for i in axes]),
cp.asarray([b.shape[i] for i in axes]))
dims = [int(d) for d in dims]
af = fft(a, dims, axes)
bf = fft(b, dims, axes)
return ifft(af * bf, dims, axes)
# Construct sporco.cupy.fft
示例15: filter
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import isrealobj [as 別名]
def filter(self, array, *args, **kwargs):
# 1-D Real Arrays
if array.ndim == 1 and np.isrealobj(array):
return self.svafilter(array, self.ov)
# 1-D Complex Arrays
if array.ndim == 1 and np.iscomplexobj(array):
return self.sva1D(array, self.ov)
# 2-D Complex Arrays
if array.ndim == 2 and np.iscomplexobj(array):
return self.sva2D(array, self.ov)
# 3-D Complex Arrays
if array.ndim == 3 and np.iscomplexobj(array):
p = array.shape
for k in range(0,p[0]):
array[k,:,:] = self.sva2D(array[k,:,:], self.ov)
return array
else:
print(" ERROR: Bad input.")
return None