开发者

numpy: query a data from masked record?

开发者 https://www.devze.com 2023-02-28 06:55 出处:网络
I have mask record like this In [41]: x Out[41]: masked_records( CHR : [12 12 12 ..., 12 12 12] SNP : [rs4980929 rs4980929 rs49开发者_C百科80929 ..., rs7975069 rs7975069 rs7975069]

I have mask record like this

In [41]: x
Out[41]: 
masked_records(
      CHR : [12 12 12 ..., 12 12 12]
      SNP : [rs4980929 rs4980929 rs49开发者_C百科80929 ..., rs7975069 rs7975069 rs7975069]
       A1 : [C C C ..., T T T]
       A2 : [T T T ..., C C C]
     TEST : [GENO TREND ALLELIC ..., ALLELIC DOM REC]
      AFF : [51/126/92 228/310 228/310 ..., 190/350 158/112 32/238]
    UNAFF : [51/136/83 238/302 238/302 ..., 180/362 148/123 32/239]
    CHISQ : [0.8427 0.3124 0.3155 ..., 0.4688 0.8398 0.000248]
       DF : [2 1 1 ..., 1 1 1]
        P : [0.6562 0.5762 0.5744 ..., 0.4935 0.3594 0.9874]
    fill_value : (999999, 'N/A', 'N', 'N', 'N/A', 'N/A', 'N/A', 1e+20, 999999, 1e+20)

How do I get value from P where TEST == 'GENO' ? If this help, 'P' field has a missing value.


It should be as simple a x['P'][x['TEST'] == 'GENO']

e.g.

import numpy as np

# Make some fake data:
x = np.zeros(10, dtype={'names':['P', 'TEST'], 'formats':[np.int, '|S5']})
x['P'] = np.arange(10)
x['TEST'] = ['GENO', 'TREND', 'ALLEL', 'DOM', 'REC', 
             'GENO', 'TREND', 'DOM', 'ALLEL', 'REC']

# Get values in field "P" where field "TEST" == "GENO":
print x['P'][x['TEST'] == 'GENO']
0

精彩评论

暂无评论...
验证码 换一张
取 消