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


Python numpy.extract方法代码示例

本文整理汇总了Python中numpy.extract方法的典型用法代码示例。如果您正苦于以下问题:Python numpy.extract方法的具体用法?Python numpy.extract怎么用?Python numpy.extract使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在numpy的用法示例。


在下文中一共展示了numpy.extract方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _cdf

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import extract [as 别名]
def _cdf(self, x, c):
        output = np.zeros(x.shape, dtype=x.dtype)
        val = (1.0+c)/(1.0-c)
        c1 = x < np.pi
        c2 = 1-c1
        xp = np.extract(c1, x)
        xn = np.extract(c2, x)
        if np.any(xn):
            valn = np.extract(c2, np.ones_like(x)*val)
            xn = 2*np.pi - xn
            yn = np.tan(xn/2.0)
            on = 1.0-1.0/np.pi*np.arctan(valn*yn)
            np.place(output, c2, on)
        if np.any(xp):
            valp = np.extract(c1, np.ones_like(x)*val)
            yp = np.tan(xp/2.0)
            op = 1.0/np.pi*np.arctan(valp*yp)
            np.place(output, c1, op)
        return output 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:21,代码来源:_continuous_distns.py

示例2: skew

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import extract [as 别名]
def skew(a, axis=0, bias=True):
    a, axis = _chk_asarray(a,axis)
    n = a.count(axis)
    m2 = moment(a, 2, axis)
    m3 = moment(a, 3, axis)
    olderr = np.seterr(all='ignore')
    try:
        vals = ma.where(m2 == 0, 0, m3 / m2**1.5)
    finally:
        np.seterr(**olderr)

    if not bias:
        can_correct = (n > 2) & (m2 > 0)
        if can_correct.any():
            m2 = np.extract(can_correct, m2)
            m3 = np.extract(can_correct, m3)
            nval = ma.sqrt((n-1.0)*n)/(n-2.0)*m3/m2**1.5
            np.place(vals, can_correct, nval)
    return vals 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:21,代码来源:mstats_basic.py

示例3: _detect_gear_level

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import extract [as 别名]
def _detect_gear_level(self, gear_level_image):
        img_level = matcher.MM_COLOR_BY_HUE(
            hue=(30 - 5, 30 + 5), visibility=(200, 255))(gear_level_image)
        cv2.imshow('level', img_level)
        img_level_hist = np.sum(img_level / 255, axis=0)
        img_level_x = np.extract(img_level_hist > 3, np.arange(1024))

        level_width = np.amax(img_level_x) - np.amin(img_level_x)

        if level_width < 10:
            return 1

        elif level_width < 40:
            return 2

        return 3

    # Sub abilities 
开发者ID:hasegaw,项目名称:IkaLog,代码行数:20,代码来源:downie.py

示例4: take

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import extract [as 别名]
def take(a, indices, axis=None, out=None):
    """Takes elements of an array at specified indices along an axis.

    This is an implementation of "fancy indexing" at single axis.

    This function does not support ``mode`` option.

    Args:
        a (cupy.ndarray): Array to extract elements.
        indices (int or array-like): Indices of elements that this function
            takes.
        axis (int): The axis along which to select indices. The flattened input
            is used by default.
        out (cupy.ndarray): Output array. If provided, it should be of
            appropriate shape and dtype.

    Returns:
        cupy.ndarray: The result of fancy indexing.

    .. seealso:: :func:`numpy.take`

    """
    # TODO(okuta): check type
    return a.take(indices, axis, out) 
开发者ID:cupy,项目名称:cupy,代码行数:26,代码来源:indexing.py

示例5: get_background_rms

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import extract [as 别名]
def get_background_rms(self):
        """
        Calculate the rms of the image. The rms is calculated from the interqurtile range (IQR), to
        reduce bias from source pixels.

        Returns
        -------
        rms : float
            The image rms.

        Notes
        -----
        The rms value is cached after first calculation.
        """
        # TODO: return a proper background RMS ignoring the sources
        # This is an approximate method suggested by PaulH.
        # I have no idea where this magic 1.34896 number comes from...
        if self._rms is None:
            # Get the pixels values without the NaNs
            data = numpy.extract(self.hdu.data > -9999999, self.hdu.data)
            p25 = scipy.stats.scoreatpercentile(data, 25)
            p75 = scipy.stats.scoreatpercentile(data, 75)
            iqr = p75 - p25
            self._rms = iqr / 1.34896
        return self._rms 
开发者ID:PaulHancock,项目名称:Aegean,代码行数:27,代码来源:fits_image.py

示例6: multiband_extract_off_diag

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import extract [as 别名]
def multiband_extract_off_diag(mtx):
    """
    extract off-diagonal entries in mtx
    The output vector is order in a column major manner

    Parameters
    ----------
    mtx: input matrix to extract the off-diagonal entries
    """
    # we transpose the matrix because the function np.extract will first flatten the matrix
    # withe ordering convention 'C' instead of 'F'!!
    Q = mtx.shape[0]
    num_bands = mtx.shape[2]
    extract_cond = np.reshape((1 - np.eye(Q)).T.astype(bool), (-1, 1), order='F')
    return np.column_stack([np.reshape(np.extract(extract_cond, mtx[:, :, band].T),
                                       (-1, 1), order='F')
                            for band in range(num_bands)]) 
开发者ID:LCAV,项目名称:pyroomacoustics,代码行数:19,代码来源:tools_fri_doa_plane.py

示例7: mtx_freq2visi

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import extract [as 别名]
def mtx_freq2visi(M, p_mic_x, p_mic_y):
    """
    build the matrix that maps the Fourier series to the visibility

    Parameters
    ----------
    M: 
        the Fourier series expansion is limited from -M to M
    p_mic_x: 
        a vector that constains microphones x coordinates
    p_mic_y: 
        a vector that constains microphones y coordinates
    """
    num_mic = p_mic_x.size
    ms = np.reshape(np.arange(-M, M + 1, step=1), (1, -1), order='F')
    p_mic_x_outer = p_mic_x[:, np.newaxis]
    p_mic_y_outer = p_mic_y[:, np.newaxis]
    p_mic_x_inner = p_mic_x[np.newaxis, :]
    p_mic_y_inner = p_mic_y[np.newaxis, :]
    extract_cond = np.reshape((1 - np.eye(num_mic)).astype(bool), (-1, 1), order='C')
    baseline_x = np.extract(extract_cond, p_mic_x_outer - p_mic_x_inner)[:, np.newaxis]
    baseline_y = np.extract(extract_cond, p_mic_y_outer - p_mic_y_inner)[:, np.newaxis]
    baseline_norm = np.sqrt(baseline_x * baseline_x + baseline_y * baseline_y)
    return (-1j) ** ms * sp.special.jv(ms, baseline_norm) * \
           np.exp(1j * ms * np.arctan2(baseline_y, baseline_x)) 
开发者ID:LCAV,项目名称:pyroomacoustics,代码行数:27,代码来源:tools_fri_doa_plane.py

示例8: build_mtx_amp

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import extract [as 别名]
def build_mtx_amp(phi_k, p_mic_x, p_mic_y):
    """
    the matrix that maps Diracs' amplitudes to the visibility

    Parameters
    ----------
    phi_k: 
        Diracs' location (azimuth)
    p_mic_x: 
        a vector that contains microphones' x-coordinates
    p_mic_y: 
        a vector that contains microphones' y-coordinates
    """
    xk, yk = polar2cart(1, phi_k[np.newaxis, :])
    num_mic = p_mic_x.size
    p_mic_x_outer = p_mic_x[:, np.newaxis]
    p_mic_y_outer = p_mic_y[:, np.newaxis]
    p_mic_x_inner = p_mic_x[np.newaxis, :]
    p_mic_y_inner = p_mic_y[np.newaxis, :]
    extract_cond = np.reshape((1 - np.eye(num_mic)).astype(bool), (-1, 1), order='C')
    baseline_x = np.extract(extract_cond, p_mic_x_outer - p_mic_x_inner)[:, np.newaxis]
    baseline_y = np.extract(extract_cond, p_mic_y_outer - p_mic_y_inner)[:, np.newaxis]
    return np.exp(-1j * (xk * baseline_x + yk * baseline_y)) 
开发者ID:LCAV,项目名称:pyroomacoustics,代码行数:25,代码来源:tools_fri_doa_plane.py

示例9: extract_off_diag

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import extract [as 别名]
def extract_off_diag(mtx):
    """
    extract off diagonal entries in mtx.
    The output vector is order in a column major manner.
    :param mtx: input matrix to extract the off diagonal entries
    :return:
    """
    # we transpose the matrix because the function np.extract will first flatten the matrix
    # withe ordering convention 'C' instead of 'F'!!
    extract_cond = np.reshape((1 - np.eye(*mtx.shape)).T.astype(bool), (-1, 1), order='F')
    return np.reshape(np.extract(extract_cond, mtx.T), (-1, 1), order='F') 
开发者ID:LCAV,项目名称:FRIDA,代码行数:13,代码来源:tools_fri_doa_plane.py

示例10: lsofcsr

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import extract [as 别名]
def lsofcsr(coo3, dtype=float, shape=None, axis=0):
  """
    Generate a list of csr matrices out of a 3-dimensional coo format 
    Args:
      coo3  : must be a tuple (data, (i1,i2,i3)) in analogy to the tuple (data, (rows,cols)) for a common coo format
      shape : a tuple of dimensions if they are known or cannot be guessed correctly from the data
      axis  : index (0,1 or 2) along which to construct the list of sparse arrays
    Returns:
      list of csr matrices
  """
  (d, it) = coo3
  assert len(it)==3
  for ia in it: assert len(d)==len(ia)
  shape = [max(ia)+1 for ia in it] if shape is None else shape
  #print( len(d) )
  #print( shape )
  
  iir = [i for i in range(len(shape)) if i!=axis]
  #print(__name__, iir)
  #print(__name__, type(it), type(it[0]==0))
  #print(__name__, it[0]==0)
  
  lsofcsr = [0] * shape[axis]
  sh = [shape[i] for i in iir]
  for i in range(shape[axis]):
    mask = it[axis]==i
    csrm = csr_matrix( (extract(mask,d), (extract(mask,it[iir[0]]),extract(mask,it[iir[1]]) )), shape=sh, dtype=dtype)
    csrm.eliminate_zeros()
    lsofcsr[i] = csrm
    
  #print(__name__, 'ttot', ttot)
  
  return lsofcsr

#
#
# 
开发者ID:pyscf,项目名称:pyscf,代码行数:39,代码来源:lsofcsr.py

示例11: place

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import extract [as 别名]
def place(arr, mask, vals):
    """
    Change elements of an array based on conditional and input values.

    Similar to ``np.copyto(arr, vals, where=mask)``, the difference is that
    `place` uses the first N elements of `vals`, where N is the number of
    True values in `mask`, while `copyto` uses the elements where `mask`
    is True.

    Note that `extract` does the exact opposite of `place`.

    Parameters
    ----------
    arr : ndarray
        Array to put data into.
    mask : array_like
        Boolean mask array. Must have the same size as `a`.
    vals : 1-D sequence
        Values to put into `a`. Only the first N elements are used, where
        N is the number of True values in `mask`. If `vals` is smaller
        than N, it will be repeated, and if elements of `a` are to be masked,
        this sequence must be non-empty.

    See Also
    --------
    copyto, put, take, extract

    Examples
    --------
    >>> arr = np.arange(6).reshape(2, 3)
    >>> np.place(arr, arr>2, [44, 55])
    >>> arr
    array([[ 0,  1,  2],
           [44, 55, 44]])

    """
    if not isinstance(arr, np.ndarray):
        raise TypeError("argument 1 must be numpy.ndarray, "
                        "not {name}".format(name=type(arr).__name__))

    return _insert(arr, mask, vals) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:43,代码来源:function_base.py

示例12: testExtractExecution

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import extract [as 别名]
def testExtractExecution(self):
        data = np.arange(12).reshape((3, 4))
        a = tensor(data, chunk_size=2)
        condition = mod(a, 3) == 0

        t = extract(condition, a)

        res = self.executor.execute_tensor(t, concat=True)[0]
        expected = np.extract(np.mod(data, 3) == 0, data)
        np.testing.assert_array_equal(res, expected) 
开发者ID:mars-project,项目名称:mars,代码行数:12,代码来源:test_indexing_execute.py

示例13: _lazywhere

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import extract [as 别名]
def _lazywhere(cond, arrays, f, fillvalue=None, f2=None):
    """
    np.where(cond, x, fillvalue) always evaluates x even where cond is False.
    This one only evaluates f(arr1[cond], arr2[cond], ...).
    For example,
    >>> a, b = np.array([1, 2, 3, 4]), np.array([5, 6, 7, 8])
    >>> def f(a, b):
        return a*b
    >>> _lazywhere(a > 2, (a, b), f, np.nan)
    array([ nan,  nan,  21.,  32.])

    Notice it assumes that all `arrays` are of the same shape, or can be
    broadcasted together.

    """
    if fillvalue is None:
        if f2 is None:
            raise ValueError("One of (fillvalue, f2) must be given.")
        else:
            fillvalue = np.nan
    else:
        if f2 is not None:
            raise ValueError("Only one of (fillvalue, f2) can be given.")

    arrays = np.broadcast_arrays(*arrays)
    temp = tuple(np.extract(cond, arr) for arr in arrays)
    tcode = np.mintypecode([a.dtype.char for a in arrays])
    out = _valarray(np.shape(arrays[0]), value=fillvalue, typecode=tcode)
    np.place(out, cond, f(*temp))
    if f2 is not None:
        temp = tuple(np.extract(~cond, arr) for arr in arrays)
        np.place(out, ~cond, f2(*temp))

    return out 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:36,代码来源:_util.py

示例14: _lazyselect

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import extract [as 别名]
def _lazyselect(condlist, choicelist, arrays, default=0):
    """
    Mimic `np.select(condlist, choicelist)`.

    Notice it assumes that all `arrays` are of the same shape, or can be
    broadcasted together.

    All functions in `choicelist` must accept array arguments in the order
    given in `arrays` and must return an array of the same shape as broadcasted
    `arrays`.

    Examples
    --------
    >>> x = np.arange(6)
    >>> np.select([x <3, x > 3], [x**2, x**3], default=0)
    array([  0,   1,   4,   0,  64, 125])

    >>> _lazyselect([x < 3, x > 3], [lambda x: x**2, lambda x: x**3], (x,))
    array([   0.,    1.,    4.,   0.,   64.,  125.])

    >>> a = -np.ones_like(x)
    >>> _lazyselect([x < 3, x > 3],
    ...             [lambda x, a: x**2, lambda x, a: a * x**3],
    ...             (x, a), default=np.nan)
    array([   0.,    1.,    4.,   nan,  -64., -125.])

    """
    arrays = np.broadcast_arrays(*arrays)
    tcode = np.mintypecode([a.dtype.char for a in arrays])
    out = _valarray(np.shape(arrays[0]), value=default, typecode=tcode)
    for index in range(len(condlist)):
        func, cond = choicelist[index], condlist[index]
        if np.all(cond is False):
            continue
        cond, _ = np.broadcast_arrays(cond, arrays[0])
        temp = tuple(np.extract(cond, arr) for arr in arrays)
        np.place(out, cond, func(*temp))
    return out 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:40,代码来源:_util.py

示例15: _stats

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import extract [as 别名]
def _stats(self, b, moments='mv'):
        mu, mu2, g1, g2 = None, None, None, None
        if 'm' in moments:
            mask = b > 1
            bt = np.extract(mask, b)
            mu = valarray(np.shape(b), value=np.inf)
            np.place(mu, mask, bt / (bt-1.0))
        if 'v' in moments:
            mask = b > 2
            bt = np.extract(mask, b)
            mu2 = valarray(np.shape(b), value=np.inf)
            np.place(mu2, mask, bt / (bt-2.0) / (bt-1.0)**2)
        if 's' in moments:
            mask = b > 3
            bt = np.extract(mask, b)
            g1 = valarray(np.shape(b), value=np.nan)
            vals = 2 * (bt + 1.0) * np.sqrt(bt - 2.0) / ((bt - 3.0) * np.sqrt(bt))
            np.place(g1, mask, vals)
        if 'k' in moments:
            mask = b > 4
            bt = np.extract(mask, b)
            g2 = valarray(np.shape(b), value=np.nan)
            vals = (6.0*np.polyval([1.0, 1.0, -6, -2], bt) /
                    np.polyval([1.0, -7.0, 12.0, 0.0], bt))
            np.place(g2, mask, vals)
        return mu, mu2, g1, g2 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:28,代码来源:_continuous_distns.py


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