Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
online_sum.py
# -*- coding: utf-8 -*-
# データ
arr_x=[0, 1 ,2 ,3 ,4 ,5 ,6 ,7 ,8 ,9 ,10,11,12]
arr_y=[20,25,40,35,50,40,35,30,25,30,45,40,50]
sz=len(arr_x)
# グラフを格納する辞書
data=dict()
# インデックス
idx=[]
# 集計用変数
temp=0
for i in range(sz):
temp+=arr_y[i] #加算
if(i%3==0):
idx.append(i)
idx_sz=len(idx)
#新しい列を作成
data[i]=dict()
data[i][i]=arr_y[i]
if idx_sz>1:
prev = idx[-2]
for j in reversed(idx[:-1]):
#新しい行に合計値をセット
data[i][j] = data[prev][j]+temp
#出力
a=data[i][j]
print("------- %d <--> %d -------" %(j,i))
print("x :",arr_x[j:i+1])
print("y :",arr_y[j:i+1])
print("sum:",a)
# クリア
temp=0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment