get ride of Recursion Error in large number of iteration and access to element of joint of 2 lists iteratively python

一世执手 提交于 2019-12-23 04:55:12

问题


I need to do iteratively (about 3 millions times) X=[X B] which B=[b1,b2,b3,b4,b5] and save this in a file to access in future.

I encounter two problems:

1- The first problem is that the size of X is size=(2,) and I do not know how to access different element (i.e. b1..b5 of each time) because all of them are supposed to be element number zero of each time! For solving this problem I have tried to use X.append(B) but I saw an error. I have tried to use X.append(B[0])...X.append(B[4]) but the problem was not solved! How I can do this?

2- The second one is that I use np.save('Xsaved.npy',X) but when I see

    `np.save('Xsaved.npy',X)
File "C:\Users\L\Anaconda3\envs\tensorflow\lib\site-packages\numpy\lib\npyio.py", line 509, in save
    pickle_kwargs=pickle_kwargs)
  File "C:\Users\L\Anaconda3\envs\tensorflow\lib\site-packages\numpy\lib\format.py", line 576, in write_array
    pickle.dump(array, fp, protocol=2, **pickle_kwargs)
RecursionError: maximum recursion depth exceeded while pickling an object

when Time is more than 450! however I need to iterate it for about 2.5 millions time. I would like to know how I could solve these two problems!

p.s. I write a pseudo code to see what I have done!

episodes=40000
T=3000000
for e in range(episodes):

    REWARDALLkol.append(REWARDALL)
    REWARDALL=[]

    X=[]

    for time_t in range(1,T+1):

        B= functioncalculatedB() #B=[b0,b1,b2,b3,b4]
        X=[X, B]

np.save('./save/X.npy',X)

来源:https://stackoverflow.com/questions/51201747/get-ride-of-recursion-error-in-large-number-of-iteration-and-access-to-element-o

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!