[英]How to calculate mean/variance/standard deviation per index of array?
I have some data like [[0, 1, 2], [0.5, 1.5, 2.5], [0.3, 1.3, 2.3]].我有一些数据,例如 [[0, 1, 2], [0.5, 1.5, 2.5], [0.3, 1.3, 2.3]]。
I am using numpy and python and I wish to calculate the mean and standard deviation for my data, per index.我正在使用 numpy 和 python 并且我希望根据索引计算我的数据的平均值和标准差。 So I wish to calculate the mean/std for (0, 0.5, 0.3) (eg index 0 of each subarray), (1, 1.5, 1.3) (eg index 1 of each subarray), and so on.
所以我希望计算 (0, 0.5, 0.3)(例如每个子数组的索引 0)、(1、1.5、1.3)(例如每个子数组的索引 1)等的均值/标准差。
Any suggestions?有什么建议么? (including how I can store the result and visualize it, maybe using graphing or matplotlib?)
(包括我如何存储结果并将其可视化,可能使用图形或 matplotlib?)
Thank you so much, in advance.非常感谢,提前。 Any introduction to packages that might solve this problem would be really helpful, as well.
任何可能解决此问题的软件包的介绍也将非常有帮助。
The various statistics functions all take an axis
argument that will allow you to calculate the statistic over a column:各种统计函数都采用
axis
参数,允许您计算列的统计信息:
import numpy as np
a = np.array([[0, 1, 2], [0.5, 1.5, 2.5], [0.3, 1.3, 2.3]])
np.mean(a, axis=0)
# array([0.26666667, 1.26666667, 2.26666667])
np.std(a, axis=0)
# array([0.20548047, 0.20548047, 0.20548047])
np.var(a, axis=0)
# array([0.04222222, 0.04222222, 0.04222222])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.