Python scipy.sort() Examples
The following are 2
code examples of scipy.sort().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
scipy
, or try the search function
.
Example #1
Source File: process_data.py From GPPVAE with Apache License 2.0 | 5 votes |
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
Example #2
Source File: distanceratioexperiment.py From aurum-datadiscovery with MIT License | 4 votes |
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))