我试图从我的分析中不一致的大数据集中删除值。
以下是我开始使用的当前方法。
例如,假设我有一个由许多元素组成的数组a
。
a = [30, 40, 200, 324, 8, 67, 789, 9, 567, 2143, 13]
idx = [(i,value) for i,value in enumerate(a) if value<=10]
print idx
>>> [(4, 8), (7, 9)]
我如何才能创建一个仅由其索引
组成的数组print idx
>>> [4, 8]
答案 0 :(得分:2)
不要在理解结果中包含该值:
idx = [i for i, v in enumerate(a) if v <= 10]
答案 1 :(得分:0)
你几乎就在那里,只使用索引:
>>> a = [30, 40, 200, 324, 8, 67, 789, 9, 567, 2143, 13]
>>> idx = [i for i, value in enumerate(a) if value<=10]
>>> idx
[4, 7]
答案 2 :(得分:-1)
def Genom_Restriksiyon(sequence="MustafaUyar", splite="5", specifity=False):
splite = int(splite)
non_id_rstx_list = []
id_rstx_list = []
upper = 0
_Treu_seq = ""
for base in seq:
if base != "\n":
_Treu_seq += base
while upper < splite:
restriction = [_Treu_seq[i:i+splite] for i in range(upper, len(seq), splite)]
position = 0
for base in restriction:
if specifity == False:
if len(base) == splite:
non_id_rstx_list.append(base)
if specifity == True:
if len(base) == splite:
id_rstx_list.append((str(upper + (splite * position)) +
" <"
+ base +
"<= "
+ str(((splite * (position + 1)) - (splite - len(base))) + upper)))
position += 1
upper += 1
if specifity == True:
return id_rstx_list
if specifity == False:
return non_id_rstx_list