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


Python numpy.ndarrary方法代碼示例

本文整理匯總了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 
開發者ID:Confusezius,項目名稱:Deep-Metric-Learning-Baselines,代碼行數:18,代碼來源:auxiliaries.py

示例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] 
開發者ID:rlworkgroup,項目名稱:garage,代碼行數:19,代碼來源:tensor_utils.py


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