Here are the examples of the python api numpy.lexsort taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
127 Examples
3
Source : kmeans.py
with MIT License
from Adamdad
with MIT License
from Adamdad
def txt2clusters(self):
all_boxes = self.txt2boxes()
result = self.kmeans(all_boxes, k=self.cluster_number)
result = result[np.lexsort(result.T[0, None])]
self.result2txt(result)
print("K anchors:\n {}".format(result))
print("Accuracy: {:.2f}%".format(
self.avg_iou(all_boxes, result) * 100))
if __name__ == "__main__":
3
Source : test_regression.py
with GNU General Public License v3.0
from adityaprakash-bobby
with GNU General Public License v3.0
from adityaprakash-bobby
def test_lexsort_invalid_sequence(self):
# Issue gh-4123
class BuggySequence(object):
def __len__(self):
return 4
def __getitem__(self, key):
raise KeyError
assert_raises(KeyError, np.lexsort, BuggySequence())
def test_pickle_py2_bytes_encoding(self):
3
Source : test_regression.py
with GNU General Public License v3.0
from adityaprakash-bobby
with GNU General Public License v3.0
from adityaprakash-bobby
def test_mem_lexsort_strings(self):
# Ticket #298
lst = ['abc', 'cde', 'fgh']
np.lexsort((lst,))
def test_fancy_index(self):
3
Source : groupby.py
with GNU General Public License v3.0
from adityaprakash-bobby
with GNU General Public License v3.0
from adityaprakash-bobby
def label_info(self):
# return the labels of items in original grouped axis
labels, _, _ = self.group_info
if self.indexer is not None:
sorter = np.lexsort((labels, self.indexer))
labels = labels[sorter]
return labels
def _get_compressed_labels(self):
3
Source : multi.py
with GNU General Public License v3.0
from adityaprakash-bobby
with GNU General Public License v3.0
from adityaprakash-bobby
def is_monotonic_increasing(self):
"""
return if the index is monotonic increasing (only equal or
increasing) values.
"""
# reversed() because lexsort() wants the most significant key last.
values = [self._get_level_values(i).values
for i in reversed(range(len(self.levels)))]
try:
sort_order = np.lexsort(values)
return Index(sort_order).is_monotonic
except TypeError:
# we have mixed types and np.lexsort is not happy
return Index(self.values).is_monotonic
@cache_readonly
3
Source : coo.py
with GNU General Public License v3.0
from adityaprakash-bobby
with GNU General Public License v3.0
from adityaprakash-bobby
def _sum_duplicates(self, row, col, data):
# Assumes (data, row, col) not in canonical format.
if len(data) == 0:
return row, col, data
order = np.lexsort((row, col))
row = row[order]
col = col[order]
data = data[order]
unique_mask = ((row[1:] != row[:-1]) |
(col[1:] != col[:-1]))
unique_mask = np.append(True, unique_mask)
row = row[unique_mask]
col = col[unique_mask]
unique_inds, = np.nonzero(unique_mask)
data = np.add.reduceat(data, unique_inds, dtype=self.dtype)
return row, col, data
def eliminate_zeros(self):
3
Source : kmeans.py
with MIT License
from Akhtar303
with MIT License
from Akhtar303
def txt2clusters(self):
all_boxes = self.txt2boxes()
result = self.kmeans(all_boxes, k=self.cluster_number)
result = result[np.lexsort(result.T[0, None])]
self.result2txt(result)
#print("K anchors:\n {}".format(result))
print("Accuracy: {:.2f}%".format(
self.avg_iou(all_boxes, result) * 100))
if __name__ == "__main__":
3
Source : generate_custom_anchors.py
with MIT License
from AlbertoSabater
with MIT License
from AlbertoSabater
def get_best_anchors(self):
all_boxes = self.txt2boxes()
num_steps = 20
best_iou, best_result = 0, None
print('Calculating optimal anchors')
for i in tqdm(range(num_steps), total=num_steps, file=sys.stdout):
result = self.kmeans(all_boxes, k=self.cluster_number)
result = result[np.lexsort(result.T[0, None])]
iou = self.avg_iou(all_boxes, result) * 100
if iou > best_iou:
best_iou = iou
best_result = result
print("Avg. IOU: {:.2f}%".format(self.avg_iou(all_boxes, best_result) * 100))
return best_result
def result2txt(self, anchors, output_filename):
3
Source : kmeans.py
with MIT License
from AntonMu
with MIT License
from AntonMu
def txt2clusters(self):
all_boxes = self.txt2boxes()
result = self.kmeans(all_boxes, k=self.cluster_number)
result = result[np.lexsort(result.T[0, None])]
self.result2txt(result)
print("K anchors:\n {}".format(result))
print(
"Accuracy: {:.2f}%".format(
self.avg_iou(
all_boxes,
result) *
100))
if __name__ == "__main__":
3
Source : triangulate.py
with GNU General Public License v3.0
from Artikash
with GNU General Public License v3.0
from Artikash
def _get_duplicate_point_indices(self):
"""Return array of indices of x,y points that are duplicates of
previous points. Indices are in no particular order.
"""
# Indices of sorted x,y points.
j_sorted = np.lexsort(keys=(self.x, self.y))
mask_duplicates = np.hstack([
False,
(np.diff(self.x[j_sorted]) == 0) &
(np.diff(self.y[j_sorted]) == 0),
])
# Array of duplicate point indices, in no particular order.
return j_sorted[mask_duplicates]
def _compute_convex_hull(self):
3
Source : run.py
with MIT License
from BlissChapman
with MIT License
from BlissChapman
def unique_rows(a):
order = np.lexsort(a.T)
a = a[order]
diff = np.diff(a, axis=0)
ui = np.ones(len(a), 'bool')
ui[1:] = (diff != 0).any(axis=1)
return a[ui]
def load_subject_series_epochs(data_path, subject_range, series_range, tmin=-0.2, tmax=0.5, baseline=(None, 0), stim_channel=None):
3
Source : monomial_basis_functions.py
with MIT License
from Cafolkes
with MIT License
from Cafolkes
def construct_basis(self):
from itertools import combinations_with_replacement, permutations
from numpy import unique, concatenate, lexsort, amax, prod, power
p = array([ii for ii in range(self.Nlift)])
combinations = array(list(combinations_with_replacement(p, self.n)))
powers = array([list(permutations(c, self.n)) for c in combinations]) # Find all permutations of powers
powers = unique(powers.reshape((powers.shape[0] * powers.shape[1], powers.shape[2])),
axis=0) # Remove duplicates
powers = concatenate((powers, amax(powers[:,:2], axis=1).reshape(-1,1)), axis=1)
powers = powers[lexsort((powers[:,1], powers[:,0], powers[:,2])), :]
powers = powers[3:3+self.Nlift,:2]
self.basis = lambda q, q_d: prod(power(q, powers.T), axis=0)
3
Source : argutils.py
with MIT License
from caizexin
with MIT License
from caizexin
def print_args(args: argparse.Namespace, parser=None):
args = vars(args)
if parser is None:
priorities = list(map(_priority, args.values()))
else:
all_params = [a.dest for g in parser._action_groups for a in g._group_actions ]
priority = lambda p: all_params.index(p) if p in all_params else len(all_params)
priorities = list(map(priority, args.keys()))
pad = max(map(len, args.keys())) + 3
indices = np.lexsort((list(args.keys()), priorities))
items = list(args.items())
print("Arguments:")
for i in indices:
param, value = items[i]
print(" {0}:{1}{2}".format(param, ' ' * (pad - len(param)), value))
print("")
3
Source : contact_map.py
with GNU Affero General Public License v3.0
from cerebis
with GNU Affero General Public License v3.0
from cerebis
def _update_positions(self):
"""
An optimisation, whenever the positional state changes, this method must be called to
maintain the current state in a separate array. This avoids unnecessary recalculation
overhead.
"""
# Masked sequences last, then by current position.
sorted_indices = np.lexsort([self.order['pos'], ~self.order['mask']])
for n, i in enumerate(sorted_indices):
self.order[i]['pos'] = n
self._positions = np.argsort(self.order['pos'])
def remap_gapless(self, gapless_indices):
3
Source : classes_scattering.py
with Apache License 2.0
from DanPorter
with Apache License 2.0
from DanPorter
def sort_hkl(self):
idx = np.lexsort((self.hkl[:, 1], self.hkl[:, 0], self.hkl[:, 2]))
self.hkl = self.hkl[idx, :]
self.q_mag = self.q_mag[idx]
self.intensity = self.intensity[idx]
def two_theta(self):
3
Source : test_regression.py
with Apache License 2.0
from dashanji
with Apache License 2.0
from dashanji
def test_lexsort_invalid_sequence(self):
# Issue gh-4123
class BuggySequence:
def __len__(self):
return 4
def __getitem__(self, key):
raise KeyError
assert_raises(KeyError, np.lexsort, BuggySequence())
def test_lexsort_zerolen_custom_strides(self):
3
Source : ops.py
with Apache License 2.0
from dashanji
with Apache License 2.0
from dashanji
def codes_info(self) -> np.ndarray:
# return the codes of items in original grouped axis
codes, _, _ = self.group_info
if self.indexer is not None:
sorter = np.lexsort((codes, self.indexer))
codes = codes[sorter]
return codes
def _get_compressed_codes(self) -> Tuple[np.ndarray, np.ndarray]:
3
Source : kmeans.py
with MIT License
from david8862
with MIT License
from david8862
def txt2clusters(self):
all_boxes = self.txt2boxes()
result = self.kmeans(all_boxes, k=self.cluster_number)
result = result[np.lexsort(result.T[0, None])]
self.result2txt(result)
print("K anchors:\n {}".format(result))
print("Accuracy: {:.2f}%".format(
self.avg_iou(all_boxes, result) * 100))
def main():
3
Source : interval.py
with GNU General Public License v3.0
from dnn-security
with GNU General Public License v3.0
from dnn-security
def argsort(
self,
ascending: bool = True,
kind: str = "quicksort",
na_position: str = "last",
*args,
**kwargs,
) -> np.ndarray:
ascending = nv.validate_argsort_with_ascending(ascending, args, kwargs)
if ascending and kind == "quicksort" and na_position == "last":
return np.lexsort((self.right, self.left))
# TODO: other cases we can use lexsort for? much more performant.
return super().argsort(
ascending=ascending, kind=kind, na_position=na_position, **kwargs
)
def fillna(
3
Source : ops.py
with GNU General Public License v3.0
from dnn-security
with GNU General Public License v3.0
from dnn-security
def codes_info(self) -> np.ndarray:
# return the codes of items in original grouped axis
ids, _, _ = self.group_info
if self.indexer is not None:
sorter = np.lexsort((ids, self.indexer))
ids = ids[sorter]
return ids
@final
3
Source : Kmeans.py
with MIT License
from feifeiwei
with MIT License
from feifeiwei
def txt2clusters(self):
# all_boxes = self.txt2boxes()
all_boxes = self.wh_arr
result = self.kmeans(all_boxes, k=self.cluster_number)
result = result[np.lexsort(result.T[0, None])]
self.result2txt(result)
print("K anchors:\n {}".format(result))
print("Accuracy: {:.2f}%".format(
self.avg_iou(all_boxes, result) * 100))
if __name__ == "__main__":
3
Source : Dataset.py
with MIT License
from fpthink
with MIT License
from fpthink
def unique_pc(self,pc):
#pc:nx3
order = np.lexsort(pc.T)
pc = pc[order]
diff = np.diff(pc, axis=0)
ui = np.ones(len(pc), 'bool')
ui[1:] = (diff != 0).any(axis=1)
return pc[ui].T
def __getitem__(self, index):
3
Source : kmeans.py
with MIT License
from fsx950223
with MIT License
from fsx950223
def txt2clusters(self):
all_boxes = self.txt2boxes()
plt.scatter(all_boxes[:1000, 0], all_boxes[:1000, 1], c='r')
result = self.kmeans(all_boxes, k=self.cluster_number)
result = result[np.lexsort(result.T[0, None])]
plt.scatter(result[:, 0], result[:, 1], c='b')
plt.show()
self.result2txt(result)
print("K anchors:\n {}".format(result))
print("Accuracy: {:.2f}%".format(self.avg_iou(all_boxes, result) * 100))
if __name__ == "__main__":
3
Source : lax_test.py
with Apache License 2.0
from google
with Apache License 2.0
from google
def testSortNumKeys(self, shape, dtype, num_keys):
rng = jtu.rand_default(self.rng())
args_maker = lambda: [rng(shape, dtype)]
lax_fun = lambda x: lax.sort(tuple(x), num_keys=num_keys)
numpy_fun = lambda x: tuple(x[:, np.lexsort(x[:num_keys][::-1])])
# self._CompileAndCheck(lax_fun, args_maker)
self._CheckAgainstNumpy(numpy_fun, lax_fun, args_maker)
@parameterized.named_parameters(jtu.cases_from_list(
3
Source : MtcnnDetector.py
with MIT License
from haoranD
with MIT License
from haoranD
def sort_rows_by_icol1(self,inarray):
idex=np.lexsort([inarray[:,0],inarray[:,1]])
a_sort=inarray[idex,:]
return a_sort
def generateBoundingBox(self,map,reg,scale,threshold):
3
Source : core.py
with BSD 3-Clause "New" or "Revised" License
from holzschu
with BSD 3-Clause "New" or "Revised" License
from holzschu
def argsort(self, axis=-1):
"""Returns the indices that would sort the time array.
This is similar to :meth:`~numpy.ndarray.argsort`, but adapted to ensure
that the full precision given by the two doubles ``jd1`` and ``jd2``
is used, and that corresponding attributes are copied. Internally,
it uses :func:`~numpy.lexsort`, and hence no sort method can be chosen.
"""
jd_approx = self.jd
jd_remainder = (self - self.__class__(jd_approx, format='jd', scale=self.scale)).jd
if axis is None:
return np.lexsort((jd_remainder.ravel(), jd_approx.ravel()))
else:
return np.lexsort(keys=(jd_remainder, jd_approx), axis=axis)
def min(self, axis=None, out=None, keepdims=False):
3
Source : main.py
with Apache License 2.0
from jahongir7174
with Apache License 2.0
from jahongir7174
def generate_anchor(self):
boxes = self.get_boxes()
result = self.generator(boxes, k=self.num_cluster)
result = result[numpy.lexsort(result.T[0, None])]
print("\nAnchors: \n{}".format(result))
print("\nFitness: {:.4f}".format(self.avg_iou(boxes, result)))
@staticmethod
3
Source : test_multiarray.py
with MIT License
from ktraunmueller
with MIT License
from ktraunmueller
def test_basic(self):
a = [1, 2, 1, 3, 1, 5]
b = [0, 4, 5, 6, 2, 3]
idx = np.lexsort((b, a))
expected_idx = np.array([0, 4, 2, 1, 3, 5])
assert_array_equal(idx, expected_idx)
x = np.vstack((b, a))
idx = np.lexsort(x)
assert_array_equal(idx, expected_idx)
assert_array_equal(x[1][idx], np.sort(x[1]))
class TestIO(object):
3
Source : test_regression.py
with MIT License
from ktraunmueller
with MIT License
from ktraunmueller
def test_mem_lexsort_strings(self, level=rlevel):
"""Ticket #298"""
lst = ['abc', 'cde', 'fgh']
np.lexsort((lst,))
def test_fancy_index(self, level=rlevel):
3
Source : test_regression.py
with Apache License 2.0
from Kushal997-das
with Apache License 2.0
from Kushal997-das
def test_lexsort_invalid_sequence(self):
# Issue gh-4123
class BuggySequence(object):
def __len__(self):
return 4
def __getitem__(self, key):
raise KeyError
assert_raises(KeyError, np.lexsort, BuggySequence())
def test_lexsort_zerolen_custom_strides(self):
3
Source : interval.py
with BSD 3-Clause "New" or "Revised" License
from leobago
with BSD 3-Clause "New" or "Revised" License
from leobago
def argsort(
self,
ascending: bool = True,
kind: str = "quicksort",
na_position: str = "last",
*args,
**kwargs,
) -> np.ndarray:
ascending = nv.validate_argsort_with_ascending(ascending, args, kwargs)
if ascending and kind == "quicksort" and na_position == "last":
return np.lexsort((self.right, self.left))
# TODO: other cases we can use lexsort for? much more performant.
return super().argsort(
ascending=ascending, kind=kind, na_position=na_position, **kwargs
)
def fillna(self, value=None, method=None, limit=None):
3
Source : ops.py
with BSD 3-Clause "New" or "Revised" License
from leobago
with BSD 3-Clause "New" or "Revised" License
from leobago
def codes_info(self) -> np.ndarray:
# return the codes of items in original grouped axis
codes, _, _ = self.group_info
if self.indexer is not None:
sorter = np.lexsort((codes, self.indexer))
codes = codes[sorter]
return codes
@final
3
Source : util.py
with Apache License 2.0
from LiangSiyuan21
with Apache License 2.0
from LiangSiyuan21
def unique_rows(a):
order = np.lexsort(a.T)
a = a[order]
diff = np.diff(a, axis=0)
ui = np.ones(len(a), 'bool')
ui[1:] = (diff != 0).any(axis=1)
return a[ui]
def label_smooth(scores, labels, n_cls):
3
Source : multi.py
with MIT License
from marcmetz
with MIT License
from marcmetz
def is_monotonic_increasing(self):
"""
return if the index is monotonic increasing (only equal or
increasing) values.
"""
# reversed() because lexsort() wants the most significant key last.
values = [
self._get_level_values(i).values for i in reversed(range(len(self.levels)))
]
try:
sort_order = np.lexsort(values)
return Index(sort_order).is_monotonic
except TypeError:
# we have mixed types and np.lexsort is not happy
return Index(self.values).is_monotonic
@cache_readonly
3
Source : kmeans_generator.py
with Apache License 2.0
from Media-Smart
with Apache License 2.0
from Media-Smart
def __call__(self, bboxes: np.ndarray):
"""
Parameters
----------
bboxes: resized_combined_bboxes
Returns
-------
"""
result = self.kmeans(bboxes, k=self.cluster_number)
result = result[np.lexsort(result.T[0, None])]
self.result2txt(result)
print("K anchors:\n {}".format(result))
print("Accuracy: {:.2f}%".format(self.avg_iou(bboxes, result) * 100))
return result
3
Source : test_regression.py
with MIT License
from mgotovtsev
with MIT License
from mgotovtsev
def test_lexsort_invalid_sequence(self):
# Issue gh-4123
class BuggySequence(object):
def __len__(self):
return 4
def __getitem__(self, key):
raise KeyError
assert_raises(KeyError, np.lexsort, BuggySequence())
def test_pickle_dtype(self,level=rlevel):
3
Source : phase.py
with GNU General Public License v3.0
from mhvk
with GNU General Public License v3.0
from mhvk
def argsort(self, axis=-1):
"""Returns the indices that would sort the phase array."""
phase_approx = self.cycle
phase_remainder = (self - phase_approx).cycle
if axis is None:
return np.lexsort((phase_remainder.ravel(), phase_approx.ravel()))
else:
return np.lexsort(keys=(phase_remainder, phase_approx), axis=axis)
# Below are basically straight copies from Time
def min(self, axis=None, out=None, keepdims=False):
3
Source : test_regression.py
with Apache License 2.0
from pierreant
with Apache License 2.0
from pierreant
def test_mem_lexsort_strings(self, level=rlevel):
# Ticket #298
lst = ['abc', 'cde', 'fgh']
np.lexsort((lst,))
def test_fancy_index(self, level=rlevel):
3
Source : multi.py
with Apache License 2.0
from pierreant
with Apache License 2.0
from pierreant
def is_monotonic_increasing(self):
"""
return if the index is monotonic increasing (only equal or
increasing) values.
"""
# reversed() because lexsort() wants the most significant key last.
values = [self._get_level_values(i).values
for i in reversed(range(len(self.levels)))]
try:
sort_order = np.lexsort(values)
return Index(sort_order).is_monotonic
except TypeError:
# we have mixed types and np.lexsort is not happy
return Index(self.values).is_monotonic
@property
3
Source : _core.py
with MIT License
from piyushpandita92
with MIT License
from piyushpandita92
def get_idx_of_observed_pareto_front_2d_min(Y):
"""
Fast algorithm for the pareto front for the case of two objectives.
:param Y: The set of observed objectives. 2D numpy array. Rows are the
number of observations and columns the numbers of objectives.
:returns: The indices of the points that belong to the Pareto front.
"""
assert Y.shape[1] == 2
idx = np.lexsort(Y.T)
idxp = _remove_dominated_2d(idx, Y)
return idxp
def get_idx_of_observed_pareto_front_2d_max(Y):
3
Source : multi_corpus.py
with Apache License 2.0
from rajarshd
with Apache License 2.0
from rajarshd
def dists(self, question, paragraphs):
text = []
for para in paragraphs:
text.append(" ".join("".join(s) for s in para.text))
try:
para_features = self.tfidf.fit_transform(text)
q_features = self.tfidf.transform([" ".join(question)])
except:
print("tfidf fit_transform threw an exception")
return [(paragraphs[i], float('inf')) for i in paragraphs]
dists = pairwise_distances(q_features, para_features, "cosine").ravel()
sorted_ix = np.lexsort(([x.start for x in paragraphs], dists)) # in case of ties, use the earlier paragraph
return [(paragraphs[i], dists[i]) for i in sorted_ix]
def dists_text(self, question, paragraph_texts):
3
Source : argutils.py
with MIT License
from sveneschlbeck
with MIT License
from sveneschlbeck
def print_args(args: argparse.Namespace, parser=None):
args = vars(args)
if parser is None:
priorities = list(map(_priority, args.values()))
else:
all_params = [a.dest for g in parser._action_groups for a in g._group_actions]
priority = lambda p: all_params.index(p) if p in all_params else len(all_params)
priorities = list(map(priority, args.keys()))
pad = max(map(len, args.keys())) + 3
indices = np.lexsort((list(args.keys()), priorities))
items = list(args.items())
print("Arguments:")
for i in indices:
param, value = items[i]
print(" {0}:{1}{2}".format(param, " " * (pad - len(param)), value))
print("")
3
Source : charges.py
with GNU General Public License v3.0
from tenpy
with GNU General Public License v3.0
from tenpy
def charge_sectors(self):
"""Return unique rows of self.charges.
Returns
-------
charges : array[QTYPE, ndim=2]
Rows are the rows of self.charges lexsorted and without duplicates.
"""
charges = self.charges.copy()
if not self.sorted:
charges = charges[np.lexsort(self.charges.T), :]
charges = charges[_find_row_differences(charges)[:-1], :]
return charges
def __str__(self):
3
Source : np_conserved.py
with GNU General Public License v3.0
from tenpy
with GNU General Public License v3.0
from tenpy
def isort_qdata(self):
"""(Lexiographically) sort ``self._qdata``; in place.
Lexsort ``self._qdata`` and ``self._data`` and set ``self._qdata_sorted = True``.
"""
if self._qdata_sorted:
return
if len(self._qdata) < 2:
self._qdata_sorted = True
return
perm = np.lexsort(self._qdata.T)
self._qdata = self._qdata[perm, :]
self._data = [self._data[p] for p in perm]
self._qdata_sorted = True
# reshaping ===============================================================
def make_pipe(self, axes, **kwargs):
3
Source : lattice.py
with GNU General Public License v3.0
from tenpy
with GNU General Public License v3.0
from tenpy
def _check_transl_invar_strength(self, mps_ijkl, strength_vals):
sort = np.lexsort(mps_ijkl.T)
mps_ijkl = mps_ijkl[sort]
strength_vals = strength_vals[sort]
min_ijkl = np.min(mps_ijkl, axis=1)
for cell_start in range(0, self.regular_lattice.N_sites, self.N_sites):
keep_cell = np.logical_and(cell_start < = min_ijkl,
min_ijkl < cell_start + self.N_sites)
if cell_start == 0:
ijkl_compare = mps_ijkl[keep_cell]
strength_compare = strength_vals[keep_cell]
else:
assert np.all(mps_ijkl[keep_cell] - cell_start == ijkl_compare)
if not np.all(np.abs(strength_vals[keep_cell] - strength_compare) < 1e-10):
raise ValueError("Not translation invariant: can't use HelicalLattice")
# most plot_* functions work, except:
def plot_coupling(self, ax, coupling=None, wrap=True, **kwargs):
3
Source : op4.py
with BSD 3-Clause "New" or "Revised" License
from twmacro
with BSD 3-Clause "New" or "Revised" License
from twmacro
def _sparse_sort(matrix):
# sparse matrix:
m, r, c, v = matrix
pv = np.lexsort((r, c)) # sort by column, then by row
rs = r[pv]
cs = c[pv]
vs = v[pv]
cols_with_data = sorted(set(cs))
return rs, cs, vs, cols_with_data
@staticmethod
3
Source : agents_multigen.py
with Apache License 2.0
from vivarium-collective
with Apache License 2.0
from vivarium-collective
def order_list_of_paths(path_list):
# make the lists equal in length:
length = max(map(len, path_list))
lol = np.array([list(path) + [None] * (length - len(path)) for path in path_list])
if lol.shape[0] > 1:
# sort by first two columns. TODO -- sort by all available columns
ind = np.lexsort((lol[:, 1], lol[:, 0]))
sorted_path_list = sorted(zip(ind, path_list))
forward_order = [idx_path[1] for idx_path in sorted_path_list]
forward_order.reverse()
return forward_order
else:
return path_list
def plot_agents_multigen(
3
Source : run_wikipedia_links.py
with MIT License
from wooden-spoon
with MIT License
from wooden-spoon
def get_packed_labels(sparse_labels):
idx = np.lexsort(sparse_labels.T)
_, lengths = np.unique(sparse_labels[:, 1], return_counts=True)
lengths = lengths.astype(np.int32, copy=False)
packed_labels = sparse_labels[idx, 0]
offsets = np.empty_like(lengths)
offsets[0] = 0
np.cumsum(lengths[:-1], out=offsets[1:])
return PackedLabels(packed_labels, lengths, offsets)
def main():
3
Source : K-means.py
with MIT License
from xu-peng-tao
with MIT License
from xu-peng-tao
def txt2clusters(self):
# all_boxes = self.csv2boxes() # 获取所有box的宽和高
all_boxes = self.txt2boxes()
result = self.kmeans(all_boxes, k=self.cluster_number)
result = result[np.lexsort(result.T[0, None])] # 对于聚类结果,按照第一维度进行从小到大排序
self.result2txt(result) #写入txt
print("K anchors:\n {}".format(result))
print("Accuracy: {:.2f}%".format(
self.avg_iou(all_boxes, result) * 100))
if __name__ == "__main__":
3
Source : read_data.py
with MIT License
from yicheng-w
with MIT License
from yicheng-w
def filter_tfidf(ques, paragraphs, stop_words):
tfidf = TfidfVectorizer(strip_accents="unicode", stop_words=stop_words)
n_to_select = 1
text = []
for para in paragraphs:
text.append(" ".join(para))
try:
para_feat = tfidf.fit_transform(text)
q_feat = tfidf.transform([" ".join(ques)])
except ValueError:
return []
dist = pairwise_distances(q_feat, para_feat, "cosine").ravel()
paragraphs = [(i, p) for i, p in enumerate(paragraphs)]
sorted_ix = np.lexsort(([x[0] for x in paragraphs], dist))
return [paragraphs[i] for i in sorted_ix[:n_to_select]]
def create_processed_wikihop_dataset_cs(config):
See More Examples