本文整理汇总了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
示例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)
示例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)
示例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)
示例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)
示例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 ''
示例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
示例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
示例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
示例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 ['']
示例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)))
示例12: sharpe
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import trim_zeros [as 别名]
def sharpe(self):
return sharpe(np.trim_zeros(self.returns().sum(axis=1)))
示例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]
示例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)
示例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)