• API
• FAQ
• Tools
• Archive
Need a unique gift idea?
A Pastebin account makes a great Christmas gift
SHARE
TWEET

# Untitled

a guest Mar 13th, 2018 58 Never
ENDING IN00days00hours00mins00secs

1. {
2.   import numpy as np
3.
4. grd_old = [ [0, 0, 0, 0],
5.             [0, 0, 0, 0],
6.             [0, 0, 0, 0],
7.             [0, 0, 0, 0] ]
8.
9.
10. chkl  = [ [1, 0],[2, 0] ]
11. chkr  = [ [1, 3],[2, 3] ]
12. chku  = [ [0, 1],[0, 2] ]
13. chkd  = [ [3, 1],[3, 2] ]
14. term  = [ [0, 0],[3, 3] ]   # terminal states
15.
16. r = -1
17. grd = [[0] * 4] * 4
18. iter = 3
19.
20. for k in range(iter):
21.     for i in range(4):
22.         for j in range(4):
23.             if [i, j] in chkl :
24.                 grd[i][j] = ( grd_old[i][j] + grd_old[i-1][j] + grd_old[i+1]    [j] + grd_old[i][j+1] + (4*r)) / 4
25.             elif [i, j] in chkr :
26.                 grd[i][j] = ( grd_old[i][j] + grd_old[i-1][j] + grd_old[i+1]    [j] + grd_old[i][j-1] + (4*r)) / 4
27.             elif [i, j] in chku :
28.                 grd[i][j] = ( grd_old[i][j] + grd_old[i+1][j] + grd_old[i][j-1] + grd_old[i][j+1] + (4*r)) / 4
29.             elif [i, j] in chkd :
30.                 grd[i][j] = ( grd_old[i][j] + grd_old[i-1][j] + grd_old[i][j-1] + grd_old[i][j+1] + (4*r)) / 4
31.             elif [i, j] in term :
32.                 grd[i][j] = 0
33.             elif [i, j] == [3, 0] :
34.                 grd[i][j] = ( (2*grd_old[i][j]) + grd_old[i-1][j] +     grd_old[i][j+1] + (4*r)) / 4
35.             elif [i, j] == [0, 3] :
36.                 grd[i][j] = ( (2*grd_old[i][j]) + grd_old[i][j-1] + grd_old[i+1][j] + (4*r)) / 4
37.             else:
38.                 grd[i][j] = ( grd_old[i-1][j] + grd_old[i+1][j] + grd_old[i][j-1] + grd_old[i][j+1] + (4*r)) / 4
39.     print(grd)
40.     print('----------------------------------------------------')
41.     grd_old = grd.copy()
42.
43. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top