当前位置: 首页>>代码示例>>Python>>正文


Python numpy.isrealobj方法代码示例

本文整理汇总了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)))))) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:25,代码来源:test_polynomial.py

示例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 
开发者ID:MLSpeech,项目名称:DeepFormants,代码行数:20,代码来源:extract_features.py

示例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 
开发者ID:fgnt,项目名称:pb_bss,代码行数:21,代码来源:gmm.py

示例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) 
开发者ID:fgnt,项目名称:pb_bss,代码行数:19,代码来源:gaussian.py

示例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 
开发者ID:fgnt,项目名称:pb_bss,代码行数:21,代码来源:gcacgmm.py

示例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 
开发者ID:bmcfee,项目名称:pumpp,代码行数:19,代码来源:tags.py

示例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 
开发者ID:CalebBell,项目名称:fluids,代码行数:23,代码来源:pychebfun.py

示例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
# ---------------------------------------------------------------- 
开发者ID:CalebBell,项目名称:fluids,代码行数:20,代码来源:pychebfun.py

示例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 
开发者ID:org-arl,项目名称:arlpy,代码行数:21,代码来源:signal.py

示例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) 
开发者ID:cokelaer,项目名称:spectrum,代码行数:19,代码来源:linear_prediction.py

示例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)) 
开发者ID:cokelaer,项目名称:spectrum,代码行数:23,代码来源:linear_prediction.py

示例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] 
开发者ID:stanfordnqp,项目名称:spins-b,代码行数:25,代码来源:creator_em.py

示例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 
开发者ID:skuschel,项目名称:postpic,代码行数:22,代码来源:datahandling.py

示例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 
开发者ID:bwohlberg,项目名称:sporco,代码行数:20,代码来源:__init__.py

示例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 
开发者ID:birgander2,项目名称:PyRAT,代码行数:26,代码来源:SVA.py


注:本文中的numpy.isrealobj方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。