本文整理汇总了Python中utool.compress函数的典型用法代码示例。如果您正苦于以下问题:Python compress函数的具体用法?Python compress怎么用?Python compress使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了compress函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: color_by_nids
def color_by_nids(graph, unique_nids=None, ibs=None, nid2_color_=None):
""" Colors edges and nodes by nid """
# TODO use ut.color_nodes
import plottool as pt
ensure_graph_nid_labels(graph, unique_nids, ibs=ibs)
node_to_nid = nx.get_node_attributes(graph, 'nid')
unique_nids = ut.unique(node_to_nid.values())
ncolors = len(unique_nids)
if (ncolors) == 1:
unique_colors = [pt.UNKNOWN_PURP]
else:
if nid2_color_ is not None:
unique_colors = pt.distinct_colors(ncolors + len(nid2_color_) * 2)
else:
unique_colors = pt.distinct_colors(ncolors)
# Find edges and aids strictly between two nids
nid_to_color = dict(zip(unique_nids, unique_colors))
if nid2_color_ is not None:
# HACK NEED TO ENSURE COLORS ARE NOT REUSED
nid_to_color.update(nid2_color_)
edge_aids = list(graph.edges())
edge_nids = ut.unflat_take(node_to_nid, edge_aids)
flags = [nids[0] == nids[1] for nids in edge_nids]
flagged_edge_aids = ut.compress(edge_aids, flags)
flagged_edge_nids = ut.compress(edge_nids, flags)
flagged_edge_colors = [nid_to_color[nids[0]] for nids in flagged_edge_nids]
edge_to_color = dict(zip(flagged_edge_aids, flagged_edge_colors))
node_to_color = ut.map_dict_vals(ut.partial(ut.take, nid_to_color), node_to_nid)
nx.set_edge_attributes(graph, 'color', edge_to_color)
nx.set_node_attributes(graph, 'color', node_to_color)
开发者ID:Erotemic,项目名称:ibeis,代码行数:31,代码来源:viz_graph.py
示例2: set_annot_lblannot_from_value
def set_annot_lblannot_from_value(ibs, aid_list, value_list, _lbltype, ensure=True):
"""
Associates the annot and lblannot of a specific type and value
Adds the lblannot if it doesnt exist.
Wrapper around convenience function for set_annot_from_lblannot_rowid
"""
assert value_list is not None
assert _lbltype is not None
if ensure:
pass
# a value consisting of an empty string or all spaces is set to the default
DEFAULT_VALUE = const.KEY_DEFAULTS[_lbltype]
EMPTY_KEY = const.EMPTY_KEY
# setting a name to DEFAULT_VALUE or EMPTY is equivalent to unnaming it
value_list_ = [DEFAULT_VALUE if value.strip() == EMPTY_KEY else value for value in value_list]
notdefault_list = [value != DEFAULT_VALUE for value in value_list_]
aid_list_to_delete = ut.get_dirty_items(aid_list, notdefault_list)
# Set all the valid valids
aids_to_set = ut.compress(aid_list, notdefault_list)
values_to_set = ut.compress(value_list_, notdefault_list)
ibs.delete_annot_relations_oftype(aid_list_to_delete, _lbltype)
# remove the relationships that have now been unnamed
# Convert names into lblannot_rowid
# FIXME: This function should not be able to set label realationships
# to labels that have not been added!!
# This is an inefficient way of getting lblannot_rowids!
lbltype_rowid_list = [ibs.lbltype_ids[_lbltype]] * len(values_to_set)
# auto ensure
lblannot_rowid_list = ibs.add_lblannots(lbltype_rowid_list, values_to_set)
# Call set_annot_from_lblannot_rowid to finish the conditional adding
ibs.set_annot_lblannot_from_rowid(aids_to_set, lblannot_rowid_list, _lbltype)
开发者ID:heroinlin,项目名称:ibeis,代码行数:31,代码来源:manual_lblannot_funcs.py
示例3: get_valid_imgsetids
def get_valid_imgsetids(ibs, min_num_gids=0, processed=None, shipped=None, is_occurrence=None):
r"""
FIX NAME imgagesetids
Returns:
list_ (list): list of all imageset ids
RESTful:
Method: GET
URL: /api/imageset/
"""
imgsetid_list = ibs._get_all_imgsetids()
if min_num_gids > 0:
num_gids_list = ibs.get_imageset_num_gids(imgsetid_list)
flag_list = [num_gids >= min_num_gids for num_gids in num_gids_list]
imgsetid_list = ut.compress(imgsetid_list, flag_list)
if processed is not None:
flag_list = ibs.get_imageset_processed_flags(imgsetid_list)
isvalid_list = [flag == 1 if processed else flag == 0 for flag in flag_list]
imgsetid_list = ut.compress(imgsetid_list, isvalid_list)
if shipped is not None:
flag_list = ibs.get_imageset_shipped_flags(imgsetid_list)
isvalid_list = [flag == 1 if shipped else flag == 0 for flag in flag_list]
imgsetid_list = ut.compress(imgsetid_list, isvalid_list)
if is_occurrence is not None:
flag_list = ibs.get_imageset_isoccurrence(imgsetid_list)
isvalid_list = [flag == is_occurrence for flag in flag_list]
imgsetid_list = ut.compress(imgsetid_list, isvalid_list)
return imgsetid_list
开发者ID:Erotemic,项目名称:ibeis,代码行数:29,代码来源:manual_imageset_funcs.py
示例4: possible_mana_combinations
def possible_mana_combinations(land_list, deck=None):
"""
CommandLine:
python -m mtgmonte.mtgutils --test-possible_mana_combinations
Example:
>>> # ENABLE_DOCTEST
>>> from mtgmonte.mtgutils import * # NOQA
>>> from mtgmonte import mtgobjs
>>> deck = mtgobjs.Deck(mtgobjs.load_cards(['Tropical Island', 'Sunken Hollow', 'Island']))
>>> land_list = mtgobjs.load_cards(['Ancient Tomb', 'Island', 'Flooded Strand', 'Flooded Strand', 'Shivan Reef'])
>>> card = land_list[-1]
>>> mana_combos = possible_mana_combinations(land_list, deck)
>>> result = (ut.repr2(mana_combos, nl=1, strvals=True, nobraces=True))
>>> print(result)
({CC}, {U}, {G}, {U}, {C}),
({CC}, {U}, {G}, {B}, {C}),
({CC}, {U}, {U}, {U}, {C}),
({CC}, {U}, {U}, {B}, {C}),
({CC}, {U}, {G}, {U}, {R}),
({CC}, {U}, {G}, {B}, {R}),
({CC}, {U}, {U}, {U}, {R}),
({CC}, {U}, {U}, {B}, {R}),
"""
from mtgmonte import mtgobjs
avail_mana = [land.mana_potential2(deck=deck, recurse=False) for land in land_list]
avail_mana = filter(len, avail_mana)
mana_combos1 = list(ut.iprod(*avail_mana))
# Encode the idea that two fetches cant fetch the same land
non_class1 = [[c for c in co if not isinstance(c, six.string_types)] for co in mana_combos1]
flags = [len(co) == 0 or len(set(co)) == len(co) for co in non_class1]
mana_combos2 = ut.compress(mana_combos1, flags)
mana_combos3 = [
[[c] if isinstance(c, mtgobjs.ManaSet) else c.mana_potential2(deck=deck) for c in co] for co in mana_combos2
]
unflat_combos3 = [list(ut.iprod(*co)) for co in mana_combos3]
mana_combos4 = ut.flatten(unflat_combos3)
# mana_combos4 = [reduce(operator.add, m) for m in mana_combos4]
# z = reduce(operator.add, m)
# import utool
# utool.embed()
# avail_mana = [land.mana_potential(deck=deck) for land in land_list]
# avail_mana = filter(len, avail_mana)
# mana_combos4 = list(ut.iprod(*avail_mana))
combo_ids = [tuple(sorted(x)) for x in mana_combos4]
flags = ut.flag_unique_items(combo_ids)
mana_combos = ut.compress(mana_combos4, flags)
# mana_combos = list(map(tuple, [''.join(c) for c in mana_combos]))
return mana_combos
开发者ID:Erotemic,项目名称:mtgmonte,代码行数:51,代码来源:mtgutils.py
示例5: get_valid_nids
def get_valid_nids(ibs, eid=None, filter_empty=False, min_pername=None):
r"""
Returns:
list_ (list): all valid names with at least one animal
(does not include unknown names)
RESTful:
Method: GET
URL: /api/name/
"""
if eid is None:
_nid_list = ibs._get_all_known_name_rowids()
else:
_nid_list = ibs.get_encounter_nids(eid)
# HACK FOR UNKNOWN. Makes things crash
#_nid_list += [0]
nid_list = _nid_list
if filter_empty:
min_pername = 1 if min_pername is None else max(min_pername, 1)
if min_pername is not None:
nAnnot_list = ibs.get_name_num_annotations(nid_list)
flag_list = np.array(nAnnot_list) >= min_pername
nid_list = ut.compress(nid_list, flag_list)
return nid_list
开发者ID:heroinlin,项目名称:ibeis,代码行数:26,代码来源:manual_name_funcs.py
示例6: get_name_exemplar_aids
def get_name_exemplar_aids(ibs, nid_list):
r"""
Returns:
list_ (list): a list of list of cids in each name
CommandLine:
python -m ibeis.control.manual_name_funcs --test-get_name_exemplar_aids
RESTful:
Method: GET
URL: /api/name/exemplar_aids/
Example:
>>> # ENABLE_DOCTEST
>>> from ibeis.control.manual_name_funcs import * # NOQA
>>> import ibeis
>>> ibs = ibeis.opendb('testdb1')
>>> aid_list = ibs.get_valid_aids()
>>> nid_list = ibs.get_annot_name_rowids(aid_list)
>>> exemplar_aids_list = ibs.get_name_exemplar_aids(nid_list)
>>> result = exemplar_aids_list
>>> print(result)
[[], [2, 3], [2, 3], [], [5, 6], [5, 6], [7], [8], [], [10], [], [12], [13]]
"""
# Get all annot ids for each name
aids_list = ibs.get_name_aids(nid_list, enable_unknown_fix=True)
# Flag any annots that are not exemplar and remove them
flags_list = ibsfuncs.unflat_map(ibs.get_annot_exemplar_flags, aids_list)
exemplar_aids_list = [ut.compress(aids, flags) for aids, flags in
zip(aids_list, flags_list)]
return exemplar_aids_list
开发者ID:heroinlin,项目名称:ibeis,代码行数:32,代码来源:manual_name_funcs.py
示例7: find_maxval_spell_sequence
def find_maxval_spell_sequence(player):
# sim land in play
# really need available mana
from mtgmonte import mtgutils
land_in_play = player.get_cards_in_play(["Land"])
nonland_in_hand = player.get_cards_in_hand(["Land"], invert=True)
land_list = land_in_play
spell_list = nonland_in_hand
max_avail_cmc = mtgutils.get_max_avail_cmc(land_list, deck=player.deck)
cmc_feasible_sequences = mtgutils.get_cmc_feasible_sequences(spell_list, max_avail_cmc)
if len(cmc_feasible_sequences) == 0:
sequence = []
value = 0
else:
mana_combos = mtgutils.possible_mana_combinations(land_list, player.deck)
flags = [mtgutils.can_cast(spell_sequence, mana_combos) for spell_sequence in cmc_feasible_sequences]
feasible_sequences = ut.compress(cmc_feasible_sequences, flags)
if len(feasible_sequences) == 0:
sequence = []
value = 0
else:
# Find best value in feasible solutions
value_list = [sum([card.get_goldfish_value() for card in combo]) for combo in feasible_sequences]
index = ut.list_argmax(value_list)
sequence = feasible_sequences[index]
value = len(sequence)
return sequence, value
开发者ID:Erotemic,项目名称:mtgmonte,代码行数:31,代码来源:mtgmonte.py
示例8: shark_misc
def shark_misc():
import ibeis
ibs = ibeis.opendb('WS_ALL')
aid_list = ibs.get_valid_aids()
flag_list = ibs.get_annot_been_adjusted(aid_list)
adjusted_aids = ut.compress(aid_list, flag_list)
return adjusted_aids
开发者ID:Erotemic,项目名称:ibeis,代码行数:7,代码来源:getshark.py
示例9: get_annot_alrids_oftype
def get_annot_alrids_oftype(ibs, aid_list, lbltype_rowid, configid=None):
"""
Get all the relationship ids belonging to the input annotations where the
relationship ids are filtered to be only of a specific lbltype/category/type
"""
alrids_list = ibs.get_annot_alrids(aid_list, configid=configid)
# Get lblannot_rowid of each relationship
lblannot_rowids_list = ibsfuncs.unflat_map(ibs.get_alr_lblannot_rowids, alrids_list)
# Get the type of each lblannot
lbltype_rowids_list = ibsfuncs.unflat_map(ibs.get_lblannot_lbltypes_rowids, lblannot_rowids_list)
# only want the nids of individuals, not species, for example
valids_list = [[typeid == lbltype_rowid for typeid in rowids] for rowids in lbltype_rowids_list]
alrids_list = [ut.compress(alrids, valids) for alrids, valids in zip(alrids_list, valids_list)]
if configid is None:
def resolution_func_first(alrid_list):
return [ alrid_list[0] ]
def resolution_func_lowest_config(alrid_list):
config_rowid_list = ibs.get_alr_config(alrid_list)
temp = sorted(list(zip(config_rowid_list, alrid_list)))
return [ temp[0][0] ]
alrids_list = [
resolution_func_first(alrid_list)
if len(alrid_list) > 1 else
alrid_list
for alrid_list in alrids_list
]
assert all([len(alrid_list) < 2 for alrid_list in alrids_list]),\
("More than one type per lbltype. ALRIDS: " + str(alrids_list) +
", ROW: " + str(lbltype_rowid) + ", KEYS:" + str(ibs.lbltype_ids))
return alrids_list
开发者ID:heroinlin,项目名称:ibeis,代码行数:32,代码来源:manual_lblannot_funcs.py
示例10: debug_depcache
def debug_depcache(ibs):
r"""
CommandLine:
python -m ibeis_flukematch.plugin --exec-debug_depcache
python -m ibeis_flukematch.plugin --exec-debug_depcache --show --no-cnn
python -m ibeis_flukematch.plugin --exec-debug_depcache --clear-all-depcache --db humbpacks
python -m ibeis_flukematch.plugin --exec-debug_depcache --show --no-cnn --db humpbacks
python -m ibeis_flukematch.plugin --exec-preproc_notch_tips --db humpbacks --no-cnn --show
Example:
>>> # SCRIPT
>>> from ibeis_flukematch.plugin import * # NOQA
>>> ibs = ibeis.opendb(defaultdb='PZ_MTEST')
>>> debug_depcache(ibs)
>>> ut.show_if_requested()
"""
print(ibs.depc)
nas_notch_deps = ibs.depc.get_dependencies('Has_Notch')
print('nas_notch_deps = %r' % (nas_notch_deps,))
te_deps = ibs.depc.get_dependencies('Trailing_Edge')
print('te_deps = %r' % (te_deps,))
notch_tip_deps = ibs.depc.get_dependencies('Notch_Tips')
print('notch_tip_deps = %r' % (notch_tip_deps,))
ibs.depc.print_schemas()
try:
ibs.depc.show_graph()
except Exception as ex:
ut.printex(ex, iswarning=True)
all_aids = ibs.get_valid_aids()
isvalid = ibs.depc.get('Has_Notch', all_aids, 'flag')
aid_list = ut.compress(all_aids, isvalid)
aid_list = aid_list[0:10]
ibs.depc.print_config_tables()
开发者ID:zmjjmz,项目名称:ibeis-flukematch-module,代码行数:35,代码来源:plugin.py
示例11: delete_empty_eids
def delete_empty_eids(ibs):
""" Removes encounters without images
Args:
ibs (IBEISController): ibeis controller object
CommandLine:
python -m ibeis.control.manual_egrelate_funcs --test-delete_empty_eids
Example:
>>> # ENABLE_DOCTEST
>>> from ibeis.control.manual_egrelate_funcs import * # NOQA
>>> import ibeis
>>> # build test data
>>> ibs = ibeis.opendb('testdb1')
>>> # execute function
>>> result = ibs.delete_empty_eids()
>>> # verify results
>>> print(result)
"""
eid_list = ibs.get_valid_eids(min_num_gids=0)
nGids_list = ibs.get_encounter_num_gids(eid_list)
is_invalid = [nGids == 0 for nGids in nGids_list]
invalid_eids = ut.compress(eid_list, is_invalid)
ibs.delete_encounters(invalid_eids)
开发者ID:heroinlin,项目名称:ibeis,代码行数:25,代码来源:manual_egrelate_funcs.py
示例12: testdata_humpbacks
def testdata_humpbacks():
import ibeis
ibs = ibeis.opendb(defaultdb='humpbacks')
all_aids = ibs.get_valid_aids()
isvalid = ibs.depc.get('Has_Notch', all_aids, 'flag')
aid_list = ut.compress(all_aids, isvalid)
aid_list = aid_list[0:10]
return ibs, aid_list
开发者ID:zmjjmz,项目名称:ibeis-flukematch-module,代码行数:8,代码来源:plugin.py
示例13: get_diffranks
def get_diffranks(rank_mat, qaids):
""" Find rows which scored differently over the various configs
FIXME: duplicated
"""
isdiff_flags = [not np.all(row == row[0]) for row in rank_mat]
diff_aids = ut.compress(qaids, isdiff_flags)
diff_rank = rank_mat.compress(isdiff_flags, axis=0)
diff_qxs = np.where(isdiff_flags)[0]
return diff_aids, diff_rank, diff_qxs
开发者ID:Erotemic,项目名称:ibeis,代码行数:9,代码来源:experiment_printres.py
示例14: inplace_filter_results
def inplace_filter_results(self, filter_pat):
import utool as ut
self.filter_pats.append(filter_pat)
# Get zipflags
flags_list = self.pattern_filterflags(filter_pat)
# Check to see if there are any survivors
flags = ut.lmap(any, flags_list)
#
found_lines_list = ut.zipcompress(self.found_lines_list, flags_list)
found_lxs_list = ut.zipcompress(self.found_lxs_list, flags_list)
#
found_fpath_list = ut.compress(self.found_fpath_list, flags)
found_lines_list = ut.compress(found_lines_list, flags)
found_lxs_list = ut.compress(found_lxs_list, flags)
# In place modification
self.found_fpath_list = found_fpath_list
self.found_lines_list = found_lines_list
self.found_lxs_list = found_lxs_list
开发者ID:Erotemic,项目名称:utool,代码行数:18,代码来源:util_project.py
示例15: get_other_nids
def get_other_nids(self):
ibs = self.ibs
all_nid_list = ibs.get_annot_name_rowids(self.all_aid_list)
unique_nid_list = ut.unique_ordered(all_nid_list)
is_unknown = ibs.is_nid_unknown(unique_nid_list)
is_name1 = [nid == self.nid1 for nid in unique_nid_list]
is_name2 = [nid == self.nid2 for nid in unique_nid_list]
is_other = ut.and_lists(*tuple(map(ut.not_list, (is_name1, is_name2, is_unknown))))
other_nid_list = ut.compress(unique_nid_list, is_other)
return other_nid_list
开发者ID:Erotemic,项目名称:ibeis,代码行数:10,代码来源:interact_name.py
示例16: get_cards_in_hand
def get_cards_in_hand(player, valid_types=None, invert=False):
card_list = player.hand
if valid_types is None:
valid_cards = card_list
else:
flags = [ut.is_superset(c.types, valid_types) for c in card_list]
if invert:
flags = ut.not_list(flags)
valid_cards = ut.compress(card_list, flags)
return valid_cards
开发者ID:Erotemic,项目名称:mtgmonte,代码行数:10,代码来源:mtgmonte.py
示例17: set_annot_lblannot_from_rowid
def set_annot_lblannot_from_rowid(ibs, aid_list, lblannot_rowid_list, _lbltype):
""" Sets items/lblannot_rowids of a list of annotations."""
# Get the alrids_list for the aids, using the lbltype as a filter
alrids_list = ibs.get_annot_alrids_oftype(aid_list, ibs.lbltype_ids[_lbltype])
# Find the aids which already have relationships (of _lbltype)
setflag_list = [len(alrids) > 0 for alrids in alrids_list]
# Add the relationship if it doesn't exist
aid_list_to_add = ut.get_dirty_items(aid_list, setflag_list)
lblannot_rowid_list_to_add = ut.get_dirty_items(lblannot_rowid_list, setflag_list)
# set the existing relationship if one already exists
alrids_list_to_set = ut.compress(alrids_list, setflag_list)
lblannot_rowid_list_to_set = ut.compress(lblannot_rowid_list, setflag_list)
# Assert each annot has only one relationship of this type
ibsfuncs.assert_singleton_relationship(ibs, alrids_list_to_set)
alrid_list_to_set = ut.flatten(alrids_list_to_set)
# Add the new relationships
ibs.add_annot_relationship(aid_list_to_add, lblannot_rowid_list_to_add)
# Set the old relationships
ibs.set_alr_lblannot_rowids(alrid_list_to_set, lblannot_rowid_list_to_set)
开发者ID:heroinlin,项目名称:ibeis,代码行数:19,代码来源:manual_lblannot_funcs.py
示例18: filter_and_relabel
def filter_and_relabel(labels, label_gids, min_imgs_per_occurence, occur_unixtimes=None):
"""
Removes clusters with too few members.
Relabels clusters-labels such that label 0 has the most members
"""
label_nGids = np.array(list(map(len, label_gids)))
label_isvalid = label_nGids >= min_imgs_per_occurence
occur_gids = ut.compress(label_gids, label_isvalid)
if occur_unixtimes is not None:
occur_unixtimes = ut.compress(occur_unixtimes, label_isvalid)
# Rebase ids so occurrence0 has the most images
# occur_ids = list(range(label_isvalid.sum()))
# else:
# sort by time instead
unixtime_arr = np.array(occur_unixtimes)
# Reorder occurrences so the oldest has the lowest number
occur_gids = ut.take(label_gids, unixtime_arr.argsort())
occur_ids = list(range(len(occur_gids)))
return occur_ids, occur_gids
开发者ID:Erotemic,项目名称:ibeis,代码行数:19,代码来源:preproc_occurrence.py
示例19: check_chip_external_storage
def check_chip_external_storage(ibs, cid_list):
chip_fpath_list = get_chip_fpath(ibs, cid_list, check_external_storage=False)
notexists_flags = [not exists(cfpath) for cfpath in chip_fpath_list]
if any(notexists_flags):
invalid_cids = ut.compress(cid_list, notexists_flags)
print('ERROR: %d CHIPS DO NOT EXIST' % (len(invalid_cids)))
print('ATTEMPING TO FIX %d / %d non-existing chip paths' % (len(invalid_cids), len(cid_list)))
ibs.delete_chips(invalid_cids)
raise controller_inject.ExternalStorageException('NON-EXISTING EXTRENAL STORAGE ERROR. REQUIRES RECOMPUTE. TRY AGAIN')
return chip_fpath_list
开发者ID:heroinlin,项目名称:ibeis,代码行数:10,代码来源:manual_chip_funcs.py
示例20: handle_cache_misses
def handle_cache_misses(ibs, getter_func, rowid_list, ismiss_list, vals_list, cache_, kwargs):
miss_indices = ut.list_where(ismiss_list)
miss_rowids = ut.compress(rowid_list, ismiss_list)
# call wrapped function
miss_vals = getter_func(ibs, miss_rowids, **kwargs)
# overwrite missed output
for index, val in zip(miss_indices, miss_vals):
vals_list[index] = val # Output write
# cache save
for rowid, val in zip(miss_rowids, miss_vals):
cache_[rowid] = val # Cache write
开发者ID:Erotemic,项目名称:ibeis,代码行数:11,代码来源:accessor_decors.py
注:本文中的utool.compress函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论