Issue
I have some data like [[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. So I wish to calculate the mean/std for (0, 0.5, 0.3) (e.g. index 0 of each subarray), (1, 1.5, 1.3) (e.g. index 1 of each subarray), and so on.
Any suggestions? (including how I can store the result and visualize it, maybe using graphing or matplotlib?)
Thank you so much, in advance. Any introduction to packages that might solve this problem would be really helpful, as well.
Solution
The various statistics functions all take an axis
argument that will allow you to calculate the statistic over a column:
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])
Answered By - Mark Answer Checked By - Senaida (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.