本文整理匯總了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 #
# //////////////// #