本文整理汇总了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
示例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))