本文整理汇总了Python中numpy.ndarrary方法的典型用法代码示例。如果您正苦于以下问题:Python numpy.ndarrary方法的具体用法?Python numpy.ndarrary怎么用?Python numpy.ndarrary使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类numpy
的用法示例。
在下文中一共展示了numpy.ndarrary方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run_kmeans
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import ndarrary [as 别名]
def run_kmeans(features, n_cluster):
"""
Run kmeans on a set of features to find <n_cluster> cluster.
Args:
features: np.ndarrary [n_samples x embed_dim], embedding training/testing samples for which kmeans should be performed.
n_cluster: int, number of cluster.
Returns:
cluster_assignments: np.ndarray [n_samples x 1], per sample provide the respective cluster label it belongs to.
"""
n_samples, dim = features.shape
kmeans = faiss.Kmeans(dim, n_cluster)
kmeans.n_iter, kmeans.min_points_per_centroid, kmeans.max_points_per_centroid = 20,5,1000000000
kmeans.train(features)
_, cluster_assignments = kmeans.index.search(features,1)
return cluster_assignments
示例2: discount_cumsum
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import ndarrary [as 别名]
def discount_cumsum(x, discount):
"""Discounted cumulative sum.
See https://docs.scipy.org/doc/scipy/reference/tutorial/signal.html#difference-equation-filtering # noqa: E501
Here, we have y[t] - discount*y[t+1] = x[t]
or rev(y)[t] - discount*rev(y)[t-1] = rev(x)[t]
Args:
x (np.ndarrary): Input.
discount (float): Discount factor.
Returns:
np.ndarrary: Discounted cumulative sum.
"""
return scipy.signal.lfilter([1], [1, float(-discount)], x[::-1],
axis=0)[::-1]