[Python] 'numpy.float64' object has no attribute 'numerator' for statistics.stdev()

Discussão em 'Python' iniciado por Stack, Março 24, 2025.

  1. Stack

    Stack Membro Participativo

    I have this function to calculate Cohen's D for some csv files



    def cohen_d(a,b):
    float_a = []
    float_b = []
    for x in a:
    try:
    float_a.append(float(x))
    except ValueError:
    return "NAN"
    for y in b:
    try:
    float_b.append(float(y))
    except ValueError:
    return "NAN"
    float_a = np.array(float_a)
    float_b = np.array(float_b)
    try:
    res=(statistics.fmean(float_a) - statistics.fmean(float_b)) / statistics.stdev(np.concatenate([float_a,float_b]))
    except ZeroDivisionError:
    res=0
    return res




    When I try to run it on my data, I systematically get this error:

    RuleException:
    AttributeError in file /work/user/cburnard/PIPELINES/ChIPseq/Snakefile, line 111:
    'numpy.float64' object has no attribute 'numerator'
    File "/work/user/cburnard/PIPELINES/ChIPseq/Snakefile", line 903, in __rule_calculate_multimapbw_indiv_scores
    File "/work/user/cburnard/PIPELINES/ChIPseq/Snakefile", line 162, in effect_size_mmb
    File "/work/user/cburnard/PIPELINES/ChIPseq/Snakefile", line 111, in cohen_d
    File "/tools/devel/python/Python-3.11.1/lib/python3.11/statistics.py", line 922, in stdev
    File "/tools/devel/python/Python-3.11.1/lib/python3.11/concurrent/futures/thread.py", line 58, in run



    Where is this error coming from? I don't know exactly on what line of data it is occurring, but in theory even if it's non-numerical due to some bug, I should still get the return "NAN" instead of this error.

    Continue reading...

Compartilhe esta Página