質問

Maybe the title seems bit confusing.

For example, there are three functions such as sin(x), 3 sine(x) and sin(x)+1. X would be from 1 to 100. How can I draw lines of mean with standard deviation (+ and -) for these three function values. I think that maybe I should calculate mean and standard deviation of three function values (sin(x), 3 sin(x) and sin(x)+1) at each x. However, I am not sure how I can do it with python. I know there are some function of standard deviation and mean in Scipy. Is that applicable for this case? Maybe this is stupid question. However, I am pretty novice. I really appreciate any help.

Best regards,

Isaac

役に立ちましたか?

解決

I'm not exactly sure what you mean, but perhaps the following is a useful example:

>>> import numpy as np
>>> x = np.arange(1,100)
>>> m = (sin(x)+1).mean()
>>> s = (sin(x)+1).std()
>>> print m, s
1.00383024876 0.710743876537

[edit after some further clarification]

If, however, you want the average per x-point of the various functions, something like this would work:

>>> y = np.array([sin(x), 3*sin(x), sin(x)+1])
>>> m = y.mean(axis=0)
>>> s = y.std(axis=0)

which would give you 100 means and 100 stddevs.

If you want the average of the combined function, you're essentially back to the first example:

>>> m = (sin(x) + 3*sin(x) + sin(x)+1).mean()
>>> s = (sin(x) + 3*sin(x) + sin(x)+1).std()
>>> print m, s
1.01915124381 3.55371938269

Which option is the one applicable for you depends on the context of your question; I have no clue about that.

他のヒント

import numpy as np

def function_1(X):
    return np.sin(X) 

def function_2(X):
    return 3. * np.sin(X) 

def function_3(X):
    return np.sin(X + 1.) 

X = np.arange(100)

# mean
print function_1(X).mean()

# std dev
print function_1(X).std()

# to plot
from matplotlib import pyplot as mp
mp.plot(X, function_1(X))
mp.hlines(function_1(X).mean(), 0, 100)
mp.show()

and so on... But do you really need to plot the "mean" of a sine function? Think about it ...

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top