本文整理汇总了Python中scipy.repeat方法的典型用法代码示例。如果您正苦于以下问题:Python scipy.repeat方法的具体用法?Python scipy.repeat怎么用?Python scipy.repeat使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类scipy
的用法示例。
在下文中一共展示了scipy.repeat方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Euclidean
# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import repeat [as 别名]
def Euclidean(feat, query=None,
is_sparse=False, is_trans=False):
""" Euclidean distance.
"""
if query is None:
(N, D) = feat.shape
dotprod = feat.dot(feat.T)
featl2norm = sp.repeat(dotprod.diagonal().reshape(1, -1), N, 0)
qryl2norm = featl2norm.T
else:
(nQ, D) = query.shape
(N, D) = feat.shape
dotprod = query.dot(feat.T)
qryl2norm = \
sp.repeat(np.multiply(query, query).sum(1).reshape(-1, 1), N, 1)
featl2norm = \
sp.repeat(np.multiply(feat, feat).sum(1).reshape(1, -1), nQ, 0)
return qryl2norm + featl2norm - 2 * dotprod
示例2: Euclidean_DML
# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import repeat [as 别名]
def Euclidean_DML(feat, M, query=None,
is_sparse=False, is_trans=False):
""" Euclidean distance with DML.
"""
(N, D) = feat.shape
dotprod = feat.dot(M).dot(feat.T)
l2norm = sp.repeat(dotprod.diagonal().reshape(1, -1), N, 0)
return l2norm + l2norm.T - 2 * dotprod
示例3: __quadratic_forms_matrix_euclidean
# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import repeat [as 别名]
def __quadratic_forms_matrix_euclidean(h1, h2):
r"""
Compute the bin-similarity matrix for the quadratic form distance measure.
The matric :math:`A` for two histograms :math:`H` and :math:`H'` of size :math:`m` and
:math:`n` respectively is defined as
.. math::
A_{m,n} = 1 - \frac{d_2(H_m, {H'}_n)}{d_{max}}
with
.. math::
d_{max} = \max_{m,n}d_2(H_m, {H'}_n)
See also
--------
quadratic_forms
"""
A = scipy.repeat(h2[:,scipy.newaxis], h1.size, 1) # repeat second array to form a matrix
A = scipy.absolute(A - h1) # euclidean distances
return 1 - (A / float(A.max()))
# //////////////// #
# Helper functions #
# //////////////// #