這有效:
CHROM = "3R"
g = allel.GenotypeDaskArray(callset[CHROM]['calldata/GT']).compute()
g_parents = g[:, [x in PARENT_SAMPLES for x in callset_all_sample_ids]]
g_parents
但這不會:
CHROM = "3R"
g = allel.GenotypeDaskArray(callset[CHROM]['calldata/GT']).compute()
g_parents = g[:, [x for x in callset_all_sample_ids]]
g_parents
它給出了這個錯誤:
IndexError Traceback (most recent call last)
<ipython-input-47-a5b9bc429c1d> in <module>
1 CHROM = "3R"
2 g = allel.GenotypeDaskArray(callset[CHROM]['calldata/GT']).compute()
----> 3 g_parents = g[:, [x for x in callset_all_sample_ids]]
4 g_parents
/share/lanzarolab/opt/conda/vgl/lib/python3.6/site-packages/allel/model/ndarray.py in __getitem__(self, item)
1478 def __getitem__(self, item):
1479 return index_genotype_array(self, item, array_cls=type(self),
-> 1480 vector_cls=GenotypeVector)
1481
1482 @property
/share/lanzarolab/opt/conda/vgl/lib/python3.6/site-packages/allel/model/generic.py in index_genotype_array(g, item, array_cls, vector_cls)
36
37 # apply indexing operation to underlying values
---> 38 out = g.values[item]
39
40 # decide whether to wrap the output, if so how
IndexError: only integers, slices (`:`), ellipsis (`...`), numpy.newaxis (`None`) and integer or boolean arrays are valid indices
我不明白為什么串列理解在第二種情況下不起作用。 callset_all_sample_ids是一個串列如下:
['F1foc13m',
'F1foc12m',
'F1foc11m',
'F1foc08m',
'F1foc06f',
'F1foc02f',
'F1foc05f',
'F1bait17m',
'F1bait08m',
'F1bait02f',
'F0male1',
'F1bait01f',
'F1foc01f',
'F1bait10m',
'F1foc03f',
'F1bait03f',
'F0female',
'F1foc10m',
'F1bait12m',
'F1bait13f',
'F1bait15m',
'F1bait04f',
'F1bait05f',
'F1bait06f',
'F1foc09m',
'F1bait14m',
'F1foc04f',
'F1bait07f',
'F1bait16m',
'F1bait09m',
'F1bait11m']
PARENT_SAMPLES 是一個串列,如下所示:
['F0female',
'F0male1']
在第一種情況下,我得到了預期的陣列,其中包含有關 F0female 和 F0male 的資訊。在第二種情況下,我希望獲得有關callset_all_sample_ids串列中所有專案的資訊。我究竟做錯了什么?!
uj5u.com熱心網友回復:
IndexError:只有整數、切片 (
:)、省略號 (...)、numpy.newaxis (None) 和整數或布爾陣列是有效索引
這解釋了為什么您的第一個示例有效:它是一個布林值串列,它是有效索引型別之一。但是,第二個示例不是布林值串列,因此您會收到錯誤訊息。
uj5u.com熱心網友回復:
你自己不是看領悟的嗎?
In [84]: [x in PARENT_SAMPLES for x in callset_all_sample_ids]
Out[84]:
[False,
False,
False,
False,
False,
...
False,
False]
In [85]: [x for x in callset_all_sample_ids]
Out[85]:
['F1foc13m',
'F1foc12m',
'F1foc11m',
'F1foc08m',
...
'F1bait16m',
'F1bait09m',
'F1bait11m']
一個是布林值串列,當用作索引時它變成了一個布爾陣列。如果尺寸合適就可以了。
第二個是字串串列。字串,單獨或在串列中,不能用作陣列索引。這就是錯誤告訴你的。
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/338369.html
上一篇:位移時保留標量資料型別
