質問編集履歴

1

コードを追加しました。

2021/11/07 04:26

投稿

nadai
nadai

スコア0

test CHANGED
File without changes
test CHANGED
@@ -26,11 +26,51 @@
26
26
 
27
27
 
28
28
 
29
- ```ここに言語名を入力
29
+ ```python
30
30
 
31
31
  ソースコード
32
32
 
33
+ ```import numpy as np
34
+
35
+
36
+
37
+ def walk(n_walker=10, nt=10):
38
+
39
+ pos = np.zeros((nt+1,n_walker),dtype=np.int32)
40
+
41
+ irand = 2*(np.random.randint(0,2,(nt,n_walker)))-1
42
+
43
+ if irand==-1:
44
+
45
+ pos=pos-1
46
+
33
- ```
47
+ else:
48
+
49
+ pos=pos+1
50
+
51
+ for walker in range(n_walker):
52
+
53
+ for step in range(nt):
54
+
55
+
56
+
57
+
58
+
59
+ return pos(sum(step)for step in n_waker)
60
+
61
+
62
+
63
+ nt = 500
64
+
65
+ n_walker = 1000
66
+
67
+ pos = walk(n_walker=n_walker,nt=nt)
68
+
69
+ print('Number of walkers',n_walker)
70
+
71
+ print('Average position:',pos.mean(n_walker))
72
+
73
+ print('Variance:',pos.var(n_walker))
34
74
 
35
75
 
36
76