0
A.append([(float(a) + float(b) + float(c))/3,
          (float(d) + float(e) + float(f))/3,
          (float(g) + float(h) + float(i))/3,
          (float(j) + float(k) + float(l))/3,
          (float(m) + float(n) + float(o))/3,
          (float(p) + float(q) + float(r))/3,
          (float(s) + float(t) + float(u))/3])


def mean(A):
    positives = [b for b in A if b >= 0]
    E.append((len(positives)) / (len(A))*100)
    if positives:
        return sum(positives) / len(positives)
    else:
        return 0

C = map(mean, zip(*A))
print C

#3 sigma check
def sigma(A):
    positives = [b for b in A if b >= 0]
    if positives:
        F.append((positives - C) / len(A))

print F

I am looking to find the standard deviation of the out put of the first chunk of code. It results in lists of seven numbers ie: [[-9999.0, -9999.0, -9999.0, -9999.0, -9999.0, -9999.0, -9999.0], [-9999.0, -9999.0, -9999.0, -9999.0, -9999.0, -9999.0, -9999.0], [0.040896, 0.018690, 0.0056206, -9999.0, 0.038722, 0.018323, -9999.0], [0.03944364, -9999.0, 0.037885, 0.014316, -9999.0]]

The second chunk of code finds the mean of the columns(['0.040170', '0.018057', '0.004782', '0.000000', '0.037378', '0.014778', '0.000000'])

I began writing the third chunk of code to find standard deviation but F prints out blank. Also I do not think I am writing the function properly to subtract each positive number by the average, any help would be appreciacted

4

1 回答 1

5

如果我正确理解您的问题,您有一个列表列表,其中每个子列表包含多个浮点数。

如果要计算数字列表的标准差:

import numpy
numpy.std(myList)

如果要计算i列表列表的第“列”中所有数字的标准差:

import numpy
numpy.std(zip(*myList)[i])

如果要排除列中的负数:

import numpy
import itertools
numpy.std([i for i in itertools.izip(*myList)[i] if i>=0])

希望这可以帮助

于 2013-07-16T18:43:06.563 回答