Created
March 10, 2017 18:22
-
-
Save fxborg/eb0a422fa500fab01f287f371995bf04 to your computer and use it in GitHub Desktop.
online_sum.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- 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