chx_specklecp.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:chxanalys 作者: yugangzhang 项目源码 文件源码
def get_his_std_from_pds( spec_pds, his_shapes=None):
    '''Y.G.Dec 22, 2016
    get spec_his, spec_std from a pandas.dataframe file
    Parameters:
        spec_pds: pandas.dataframe, contains columns as 'count', 
                        spec_his (as 'his_level_0_q_0'), spec_std (as 'std_level_0_q_0')
        his_shapes: the shape of the returned spec_his, if None, shapes = (2, (len(spec_pds.keys)-1)/4) )
    Return:
        spec_his: array, shape as his_shapes
        spec_std, array, shape as his_shapes  
    '''
    spkeys = list( spec_pds.keys() )
    if his_shapes is None:
        M,N = 2, int( (len(spkeys)-1)/4 )
    #print(M,N)
    spec_his = np.zeros( [M,N], dtype=np.object)
    spec_std = np.zeros( [M,N], dtype=np.object)
    for i in range(M):
        for j in range(N):
            spec_his[i,j] = np.array( spec_pds[ spkeys[1+ i*N + j] ][ ~np.isnan( spec_pds[ spkeys[1+ i*N + j] ] )] )
            spec_std[i,j] = np.array( spec_pds[ spkeys[1+ 2*N + i*N + j]][ ~np.isnan( spec_pds[ spkeys[1+ 2*N + i*N + j]]  )] )
    return spec_his, spec_std
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号