Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix IndexError: index 2 is out of bounds for axis 0 with size 2 #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

HuangFuSL
Copy link

Fix

用下边的代码生成数据,然后运行run.py会报IndexError: index 2 is out of bounds for axis 0 with size 2,这里进行修复。

import csv

from scipy.stats import norm

def Residual():
    while True:
        yield norm.rvs(0, 1)

def GenerateData():
    # Variables: X1, X2, X3, X4, X5, X6
    # Relationships: (X1 + X2) -> X3
    #                X3 -> X4
    #                X3 -> X5
    #                (X4 + X5) -> X6

    X1 = norm.rvs(5, 3, 10000)
    X2 = norm.rvs(10, 4, 10000)
    X3 = [x1 + x2 + r for x1, x2, r in zip(X1, X2, Residual())]
    X4 = [2 * x3 + r for x3, r in zip(X3, Residual())]
    X5 = [3 * x3 + r for x3, r in zip(X3, Residual())]
    X6 = [4 * x4 + 2 * x5 + r for x4, x5, r in zip(X4, X5, Residual())]
    return [
        {'X1': x1, 'X2': x2, 'X3': x3, 'X4': x4, 'X5': x5, 'X6': x6}
        for x1, x2, x3, x4, x5, x6 in zip(X1, X2, X3, X4, X5, X6)
    ]

if __name__ == '__main__':
    with open('data/test.csv', 'w', newline='') as f:
        writer = csv.DictWriter(f, fieldnames=['X1', 'X2', 'X3', 'X4', 'X5', 'X6'])
        writer.writeheader()
        writer.writerows(GenerateData())

Fix: `IndexError: index 2 is out of bounds for axis 0 with size 2`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant