简体   繁体   English

如何计算每个数组索引的均值/方差/标准差?

[英]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.

相关问题 如何在python中计算输出的均值,众数,方差,标准差等? - How to calculate mean, mode, variance, standard deviation etc. of output in python? 如何使用numpy计算不规则形状的数组的均值和标准差 - How to use numpy to calculate mean and standard deviation of an irregular shaped array 如何计算相似矩阵的均值和标准差? - How to calculate the mean and standard deviation of similarity matrix? 如何计算一组图像的均值和标准差 - How to calculate mean and standard deviation of a set of images 给定一个数字计数器,如何有效地计算方差或标准差? - How to calculate efficiently the variance or standard deviation given a counter of numbers? 具有不同标准偏差和每行平均值的 Numpy 数组 - Numpy array with different standard deviation and mean per row 如何计算给定 PySpark DataFrame 的均值和标准差? - How to calculate mean and standard deviation given a PySpark DataFrame? 如何一次性计算多个数据框的均值和标准差? - How to calculate the mean and standard deviation of multiple dataframes at one go? 如何计算字典中多个矩阵的均值/中值/标准差? - How to calculate the mean/median/standard deviation of multiple matrices in a dictionary? 给定均值和标准差,如何计算正态分布的概率? - How to calculate probability in a normal distribution given mean & standard deviation?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM