简体   繁体   English

平均负数python

[英]average negative number python

I need the average of 3 vectors in a file. 我需要文件中3个向量的平均值。 This is the file: 这是文件:

7.308017466911098700e-01 -5.497365223199360800e-01 -1.324069582379517300e-01
7.142889846599955700e-01 -5.300077858149733200e-01 -1.214793135300424200e-01
7.142889846599955700e-01 -5.300077858149733200e-01 -1.214793135300424200e-01
7.142889846599955700e-01 -5.300077858149733200e-01 -1.214793135300424200e-01
6.835045107440532700e-01 -4.980522174917749700e-01 -1.158373119954510000e-01
6.835045107440532700e-01 -4.980522174917749700e-01 -1.158373119954510000e-01
6.835045107440532700e-01 -4.980522174917749700e-01 -1.158373119954510000e-01
6.835045107440532700e-01 -4.980522174917749700e-01 -1.158373119954510000e-01
7.440304087049756100e-01 -5.568396579851897500e-01 -1.014631831749943100e-01
7.021751417881535500e-01 -6.350121671924353600e-01 -5.052342816781073300e-02

As you can see the second column contains only negative numbers. 如您所见,第二列仅包含负数。 When I try to average with the code: 当我尝试对代码求平均值时:

with open(myfile) as fin:
    for line in fin:
        vec.append(float(line.split()[1]))
    mean1=np.mean(vec)
    print mean1

I get a positive number! 我得到一个正数!

Is there something with numpy.mean? numpy.mean有东西吗?

I've tested it, and the code works as expected. 我已经对其进行了测试,并且代码按预期工作。 Make sure vec is empty at the start. 确保vec在开始时为空。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM