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


Python scipy.sort方法代碼示例

本文整理匯總了Python中scipy.sort方法的典型用法代碼示例。如果您正苦於以下問題:Python scipy.sort方法的具體用法?Python scipy.sort怎麽用?Python scipy.sort使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在scipy的用法示例。


在下文中一共展示了scipy.sort方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: import_data

# 需要導入模塊: import scipy [as 別名]
# 或者: from scipy import sort [as 別名]
def import_data(size=128):

    files = []
    orients = ["00F", "30L", "30R", "45L", "45R", "60L", "60R", "90L", "90R"]
    for orient in orients:
        _files = glob.glob(os.path.join(data_dir, "*/*_%s.jpg" % orient))
        files = files + _files
    files = sp.sort(files)

    D1id = []
    D2id = []
    Did = []
    Rid = []
    Y = sp.zeros([len(files), size, size, 3], dtype=sp.uint8)
    for _i, _file in enumerate(files):
        y = imread(_file)
        y = imresize(y, size=[size, size], interp="bilinear")
        Y[_i] = y
        fn = _file.split(".jpg")[0]
        fn = fn.split("/")[-1]
        did1, did2, rid = fn.split("_")
        Did.append(did1 + "_" + did2)
        Rid.append(rid)
    Did = sp.array(Did, dtype="|S100")
    Rid = sp.array(Rid, dtype="|S100")

    RV = {"Y": Y, "Did": Did, "Rid": Rid}
    return RV 
開發者ID:fpcasale,項目名稱:GPPVAE,代碼行數:30,代碼來源:process_data.py

示例2: __init__

# 需要導入模塊: import scipy [as 別名]
# 或者: from scipy import sort [as 別名]
def __init__(self, N, vectors, coverage_ratio=0.2):
        """
        Performs exact nearest neighbour search on the data set.

        vectors can either be a numpy matrix with all the vectors
        as columns OR a python array containing the individual
        numpy vectors.
        """
        # We need a dict from vector string representation to index
        self.vector_dict = {}
        self.N = N
        self.coverage_ratio = coverage_ratio

        # Get numpy array representation of input
        self.vectors = numpy_array_from_list_or_numpy_array(vectors)

        # Build map from vector string representation to vector
        for index in range(self.vectors.shape[1]):
            self.vector_dict[self.__vector_to_string(
                self.vectors[:, index])] = index

        # Get transposed version of vector matrix, so that the rows
        # are the vectors (needed by cdist)
        vectors_t = numpy.transpose(self.vectors)

        # Determine the indices of query vectors used for comparance
        # with approximated search.
        query_count = numpy.floor(self.coverage_ratio *
                                  self.vectors.shape[1])
        self.query_indices = []
        for k in range(int(query_count)):
            index = numpy.floor(k * (self.vectors.shape[1] / query_count))
            index = min(index, self.vectors.shape[1] - 1)
            self.query_indices.append(int(index))

        print('\nStarting exact search (query set size=%d)...\n' % query_count)

        # For each query vector get radius of closest N neighbours
        self.nearest_radius = {}
        self.exact_search_time_per_vector = 0.0

        for index in self.query_indices:

            v = vectors_t[index, :].reshape(1, self.vectors.shape[0])
            exact_search_start_time = time.time()
            D = cdist(v, vectors_t, 'euclidean')

            # Get radius of closest N neighbours
            self.nearest_radius[index] = scipy.sort(D)[0, N]

            # Save time needed for exact search
            exact_search_time = time.time() - exact_search_start_time
            self.exact_search_time_per_vector += exact_search_time

        print('\Done with exact search...\n')

        # Normalize search time
        self.exact_search_time_per_vector /= float(len(self.query_indices)) 
開發者ID:mitdbg,項目名稱:aurum-datadiscovery,代碼行數:60,代碼來源:distanceratioexperiment.py


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