當前位置: 首頁>>代碼示例>>Python>>正文


Python numpy.trim_zeros方法代碼示例

本文整理匯總了Python中numpy.trim_zeros方法的典型用法代碼示例。如果您正苦於以下問題:Python numpy.trim_zeros方法的具體用法?Python numpy.trim_zeros怎麽用?Python numpy.trim_zeros使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在numpy的用法示例。


在下文中一共展示了numpy.trim_zeros方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: split_indices

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import trim_zeros [as 別名]
def split_indices(dataset, num_children):
    """Splits indices between children

    Args:
        dataset: Dataset object
        num_children: Number of children to split samples between

    Returns:
        indices_split: A list of evenly split indices
    """

    all_indices = np.arange(dataset.num_samples)

    # Pad indices to divide evenly
    length_padding = (-len(all_indices)) % num_children
    padded_indices = np.concatenate((all_indices,
                                     np.zeros(length_padding,
                                              dtype=np.int32)))

    # Split and trim last set of indices to original length
    indices_split = np.split(padded_indices, num_children)
    indices_split[-1] = np.trim_zeros(indices_split[-1])

    return indices_split 
開發者ID:kujason,項目名稱:avod,代碼行數:26,代碼來源:gen_mini_batches.py

示例2: get_unique_labels

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import trim_zeros [as 別名]
def get_unique_labels(label_image):
    """
    Returns all possible ROI labels from ``label_image``

    Parameters
    ----------
    label_image : niimg-like object
        ROI image, where each ROI is identified with a unique integer ID

    Returns
    -------
    labels : np.ndarray
        Integer labels of all ROIS found within ``label_image``
    """

    label_image = check_img(label_image)
    return np.trim_zeros(np.unique(label_image.dataobj)).astype(int) 
開發者ID:rmarkello,項目名稱:abagen,代碼行數:19,代碼來源:utils.py

示例3: predict_one_component

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import trim_zeros [as 別名]
def predict_one_component(self, team_1, team_2, neutral=False):
        """
        Returns team 1's probability of winning
        """
        if self.latent_variables.estimated is False:
            raise Exception("No latent variables estimated!")
        else:
            if type(team_1) == str:
                team_1_ability = np.trim_zeros(self._model_abilities(self.latent_variables.get_z_values()).T[self.team_dict[team_1]], trim='b')[-1]
                team_2_ability = np.trim_zeros(self._model_abilities(self.latent_variables.get_z_values()).T[self.team_dict[team_2]], trim='b')[-1]
 
            else:
                team_1_ability = np.trim_zeros(self._model_abilities(self.latent_variables.get_z_values()).T[team_1], trim='b')[-1]
                team_2_ability = np.trim_zeros(self._model_abilities(self.latent_variables.get_z_values()).T[team_2], trim='b')[-1]

        t_z = self.transform_z()

        if neutral is False:
            return self.link(t_z[0] + team_1_ability - team_2_ability)
        else:
            return self.link(team_1_ability - team_2_ability) 
開發者ID:RJT1990,項目名稱:pyflux,代碼行數:23,代碼來源:gasrank.py

示例4: predict_two_components

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import trim_zeros [as 別名]
def predict_two_components(self, team_1, team_2, team_1b, team_2b, neutral=False):
        """
        Returns team 1's probability of winning
        """
        if self.latent_variables.estimated is False:
            raise Exception("No latent variables estimated!")
        else:
            if type(team_1) == str:
                team_1_ability = np.trim_zeros(self._model_abilities(self.latent_variables.get_z_values())[0].T[self.team_dict[team_1]], trim='b')[-1]
                team_2_ability = np.trim_zeros(self._model_abilities(self.latent_variables.get_z_values())[0].T[self.team_dict[team_2]], trim='b')[-1]
                team_1_b_ability = np.trim_zeros(self._model_abilities(self.latent_variables.get_z_values())[1].T[self.team_dict[team_1]], trim='b')[-1]
                team_2_b_ability = np.trim_zeros(self._model_abilities(self.latent_variables.get_z_values())[1].T[self.team_dict[team_2]], trim='b')[-1]
  
            else:
                team_1_ability = np.trim_zeros(self._model_abilities(self.latent_variables.get_z_values())[0].T[team_1], trim='b')[-1]
                team_2_ability = np.trim_zeros(self._model_abilities(self.latent_variables.get_z_values())[0].T[team_2], trim='b')[-1]
                team_1_b_ability = np.trim_zeros(self._model_abilities(self.latent_variables.get_z_values())[1].T[team_1_b], trim='b')[-1]
                team_2_b_ability = np.trim_zeros(self._model_abilities(self.latent_variables.get_z_values())[1].T[team_2_b], trim='b')[-1]

        t_z = self.transform_z()

        if neutral is False:
            return self.link(t_z[0] + team_1_ability - team_2_ability + team_1_b_ability - team_2_b_ability)
        else:
            return self.link(team_1_ability - team_2_ability + team_1_b_ability - team_2_b_ability) 
開發者ID:RJT1990,項目名稱:pyflux,代碼行數:27,代碼來源:gasrank.py

示例5: assert_numden_almost_equal

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import trim_zeros [as 別名]
def assert_numden_almost_equal(self, n1, n2, d1, d2):
        n1[np.abs(n1) < 1e-10] = 0.
        n1 = np.trim_zeros(n1)
        d1[np.abs(d1) < 1e-10] = 0.
        d1 = np.trim_zeros(d1)
        n2[np.abs(n2) < 1e-10] = 0.
        n2 = np.trim_zeros(n2)
        d2[np.abs(d2) < 1e-10] = 0.
        d2 = np.trim_zeros(d2)
        np.testing.assert_array_almost_equal(n1, n2)
        np.testing.assert_array_almost_equal(d2, d2) 
開發者ID:python-control,項目名稱:python-control,代碼行數:13,代碼來源:minreal_test.py

示例6: reverse

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import trim_zeros [as 別名]
def reverse(self, x):
    """Reverses output of transform back to text.

    Args:
      x: iterator or matrix of integers. Document representation in bytes.

    Yields:
      Iterators of utf-8 strings.
    """
    for data in x:
      document = np.trim_zeros(data.astype(np.int8), trim='b').tostring()
      try:
        yield document.decode('utf-8')
      except UnicodeDecodeError:
        yield '' 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:17,代碼來源:text.py

示例7: unpad_zeros

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import trim_zeros [as 別名]
def unpad_zeros(l):
    out = []
    for tags in l:
        out.append([np.trim_zeros(line) for line in tags])
    return out

# 將不滿足長度的句子填充0 
開發者ID:koala-ai,項目名稱:tensorflow_nlp,代碼行數:9,代碼來源:data_utils.py

示例8: decode_chars

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import trim_zeros [as 別名]
def decode_chars(idx, idx2chars):
    out = []
    for line in idx:
        line = np.trim_zeros(line)
        out.append([idx2chars[item] for item in line])
    return out 
開發者ID:koala-ai,項目名稱:tensorflow_nlp,代碼行數:8,代碼來源:data_utils.py

示例9: haroldpolydiv

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import trim_zeros [as 別名]
def haroldpolydiv(dividend, divisor):
    """
    Polynomial division wrapped around :func:`scipy.signal.deconvolve`
    function. Takes two arguments and divides the first
    by the second.

    Parameters
    ----------
    dividend : (n,) array_like
        The polynomial to be divided
    divisor : (m,) array_like
        The polynomial that divides

    Returns
    -------
    factor : ndarray
        The resulting polynomial coeffients of the factor
    remainder : ndarray
        The resulting polynomial coefficients of the remainder

    Examples
    --------

    >>> a = np.array([2, 3, 4 ,6])
    >>> b = np.array([1, 3, 6])
    >>> haroldpolydiv(a, b)
    (array([ 2., -3.]), array([ 1., 24.]))
    >>> c = np.array([1, 3, 3, 1])
    >>> d = np.array([1, 2, 1])
    >>> haroldpolydiv(c, d)
    (array([1., 1.]), array([], dtype=float64))

    """
    h_factor, h_remainder = (np.trim_zeros(x, 'f') for x
                             in sig.deconvolve(dividend, divisor))

    return h_factor, h_remainder 
開發者ID:ilayn,項目名稱:harold,代碼行數:39,代碼來源:_polynomial_ops.py

示例10: to_str

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import trim_zeros [as 別名]
def to_str(idx_arrays, lex):
    retval = []
    if 1 == idx_arrays.ndim:
        idx_arrays = np.expand_dims(idx_arrays, 0)
    for g in idx_arrays:
        g = np.trim_zeros(g).tolist()
        g = [item for item in g if item > 1]
        if len(g) > 0:
            g = map(lambda x: lex[x], g)
            retval.append(' '.join(g))
    return retval if 0 < len(retval) else [''] 
開發者ID:xingdi-eric-yuan,項目名稱:MatchLSTM-PyTorch,代碼行數:13,代碼來源:generic.py

示例11: gross_sharpe

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import trim_zeros [as 別名]
def gross_sharpe(self):
        return sharpe(np.trim_zeros((self.position_returns() - self.transaction_returns()).sum(axis=1))) 
開發者ID:chrism2671,項目名稱:PyTrendFollow,代碼行數:4,代碼來源:accountcurve.py

示例12: sharpe

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import trim_zeros [as 別名]
def sharpe(self):
        return sharpe(np.trim_zeros(self.returns().sum(axis=1))) 
開發者ID:chrism2671,項目名稱:PyTrendFollow,代碼行數:4,代碼來源:accountcurve.py

示例13: losses

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import trim_zeros [as 別名]
def losses(self):
        return [z for z in np.trim_zeros(self.returns()).sum(axis=1) if z<0] 
開發者ID:chrism2671,項目名稱:PyTrendFollow,代碼行數:4,代碼來源:accountcurve.py

示例14: sortino

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import trim_zeros [as 別名]
def sortino(self):
        return np.trim_zeros(self.returns().sum(axis=1)).mean()/np.std(self.losses())*np.sqrt(252) 
開發者ID:chrism2671,項目名稱:PyTrendFollow,代碼行數:4,代碼來源:accountcurve.py

示例15: annual_vol

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import trim_zeros [as 別名]
def annual_vol(self):
        return "{0:,.4f}".format(np.trim_zeros(self.returns()).sum(axis=1).std() * np.sqrt(252)/self.capital) 
開發者ID:chrism2671,項目名稱:PyTrendFollow,代碼行數:4,代碼來源:accountcurve.py


注:本文中的numpy.trim_zeros方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。