Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Loops 计算移动值范围内的平均值和标准偏差_Loops_Iteration_Data Visualization_Mean_Standard Deviation - Fatal编程技术网

Loops 计算移动值范围内的平均值和标准偏差

Loops 计算移动值范围内的平均值和标准偏差,loops,iteration,data-visualization,mean,standard-deviation,Loops,Iteration,Data Visualization,Mean,Standard Deviation,BLUF:(使用Python3.0)以0.25为增量,我希望计算并存储一系列值的平均值/std,以便以后绘制它们或进行进一步分析 计算平均值/std很容易,但我无法正确地使用算法在值范围内正确迭代 数据: 到目前为止,我得到的是标准化的玩具数据,看起来像是散弹枪爆炸,其中一个目标区域以0.25的增量隔离在黑线之间: import csv import pandas as pd import numpy as np import matplotlib.pyplot as plt from mat

BLUF:(使用Python3.0)以0.25为增量,我希望计算并存储一系列值的平均值/std,以便以后绘制它们或进行进一步分析

计算平均值/std很容易,但我无法正确地使用算法在值范围内正确迭代

数据:

到目前为止,我得到的是标准化的玩具数据,看起来像是散弹枪爆炸,其中一个目标区域以0.25的增量隔离在黑线之间:

import csv
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt 
from matplotlib import pyplot as plt
import seaborn as sns
Data=pd.read_csv("Data.csv")

g = sns.jointplot(x="x", y="y", data=Data)

bottom_lim = 0
top_lim = 0.25
temp = Data.loc[(Data.y>=bottom_lim)&(Data.y<top_lim)]
g.ax_joint.axhline(top_lim, c='k', lw=2)
g.ax_joint.axhline(bottom_lim, c='k', lw=2)

# we have to create a secondary y-axis to the joint-plot, otherwise the kde 
might be very small compared to the scale of the original y-axis
ax_joint_2 = g.ax_joint.twinx()
sns.kdeplot(temp.x, shade=True, color='red', ax=ax_joint_2, legend=False)
ax_joint_2.spines['right'].set_visible(False)
ax_joint_2.spines['top'].set_visible(False)
ax_joint_2.yaxis.set_visible(False)

# calculating the StdDev of the y-axis band above
S = temp.std()
M = temp.mean()
print("StdDev", S)
print("Mean", M)

但在循环中执行此操作以覆盖从0到8的整个“y”变量范围。我希望以一种格式保存这些结果,以便以后打印或进一步操作它们(列表、数组等)。

一个简单的
,而
循环可以实现我们在这里想要的:

bottom_lim, top_lim = 0, 0.25
g = sns.jointplot(x="x", y="y", data=data)
while bottom_lim < 7.75 and top_lim < 8:
    temp = data.loc[(data.y>=bottom_lim)&(data.y<top_lim)]
    g.ax_joint.axhline(top_lim, c='g', lw=2)
    g.ax_joint.axhline(bottom_lim, c='g', lw=2)
    ax_joint_2 = g.ax_joint.twinx()
    sns.kdeplot(temp.x, shade=True, color='green', ax=ax_joint_2, legend=False)
    ax_joint_2.spines['right'].set_visible(False)
    ax_joint_2.spines['top'].set_visible(False)
    ax_joint_2.yaxis.set_visible(False)
    # calculating the StdDev of the band above
    S = temp.std()
    M = temp.mean()
    print("StdDev", S)
    print("Mean", M)
    bottom_lim+=0.25
    top_lim+=0.25
bottom_lim,top_lim=0,0.25
g=sns.jointplot(x=“x”,y=“y”,数据=数据)
当底部边缘<7.75和顶部边缘<8时:
temp=data.loc[(data.y>=bottom_lim)和(data.y
bottom_lim, top_lim = 0, 0.25
g = sns.jointplot(x="x", y="y", data=data)
while bottom_lim < 7.75 and top_lim < 8:
    temp = data.loc[(data.y>=bottom_lim)&(data.y<top_lim)]
    g.ax_joint.axhline(top_lim, c='g', lw=2)
    g.ax_joint.axhline(bottom_lim, c='g', lw=2)
    ax_joint_2 = g.ax_joint.twinx()
    sns.kdeplot(temp.x, shade=True, color='green', ax=ax_joint_2, legend=False)
    ax_joint_2.spines['right'].set_visible(False)
    ax_joint_2.spines['top'].set_visible(False)
    ax_joint_2.yaxis.set_visible(False)
    # calculating the StdDev of the band above
    S = temp.std()
    M = temp.mean()
    print("StdDev", S)
    print("Mean", M)
    bottom_lim+=0.25
    top_lim+=0.25