I need the average of 3 vectors in a file. 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?
I've tested it, and the code works as expected. Make sure vec
is empty at the start.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.