回答編集履歴

6

import 抜けてた

2021/12/02 00:28

投稿

taront
taront

スコア59

test CHANGED
@@ -90,6 +90,8 @@
90
90
 
91
91
  ```
92
92
 
93
+ import numpy as np
94
+
93
95
  import random
94
96
 
95
97
  import more_itertools

5

ミス修正

2021/12/02 00:28

投稿

taront
taront

スコア59

test CHANGED
@@ -114,7 +114,7 @@
114
114
 
115
115
  def get_ratio(r_min:float, r_max:float, arr:np.ndarray)->float:
116
116
 
117
- pick_elems = arr[(r_min <= orbit) & (arr < r_max)]
117
+ pick_elems = arr[(r_min <= arr) & (arr < r_max)]
118
118
 
119
119
  m_hist, _ = np.histogram(pick_elems, range=(r_min, r_max), bins=len(pick_elems))
120
120
 

4

修正

2021/12/02 00:24

投稿

taront
taront

スコア59

test CHANGED
@@ -112,7 +112,7 @@
112
112
 
113
113
 
114
114
 
115
- def get_ratio(r_min:float, r_max:float, arr:np.ndarray):
115
+ def get_ratio(r_min:float, r_max:float, arr:np.ndarray)->float:
116
116
 
117
117
  pick_elems = arr[(r_min <= orbit) & (arr < r_max)]
118
118
 

3

追加

2021/12/02 00:18

投稿

taront
taront

スコア59

test CHANGED
@@ -69,3 +69,65 @@
69
69
  print(results)
70
70
 
71
71
  ```
72
+
73
+
74
+
75
+
76
+
77
+ [補足]
78
+
79
+ 少しpythonっぽくしてみました
80
+
81
+
82
+
83
+ ```
84
+
85
+ !pip install more-itertools
86
+
87
+ ```
88
+
89
+
90
+
91
+ ```
92
+
93
+ import random
94
+
95
+ import more_itertools
96
+
97
+
98
+
99
+ random.seed(110)
100
+
101
+ orbit = np.asarray([random.uniform(0,1) for _ in range(10000000)])
102
+
103
+ print('start')
104
+
105
+
106
+
107
+ N = 100
108
+
109
+
110
+
111
+ hist, bins = np.histogram(orbit, range=(0, 1), bins=N)
112
+
113
+
114
+
115
+ def get_ratio(r_min:float, r_max:float, arr:np.ndarray):
116
+
117
+ pick_elems = arr[(r_min <= orbit) & (arr < r_max)]
118
+
119
+ m_hist, _ = np.histogram(pick_elems, range=(r_min, r_max), bins=len(pick_elems))
120
+
121
+ return np.count_nonzero(m_hist)/len(m_hist)
122
+
123
+
124
+
125
+ results = [get_ratio(r[0], r[1], orbit) for r in more_itertools.windowed(bins,2,step = 1)]
126
+
127
+
128
+
129
+ print(len(results))
130
+
131
+ print(results)
132
+
133
+ ```

2

import 抜けてた

2021/12/02 00:16

投稿

taront
taront

スコア59

test CHANGED
@@ -5,6 +5,8 @@
5
5
  ```
6
6
 
7
7
  import numpy as np
8
+
9
+ import random
8
10
 
9
11
 
10
12
 

1

ミス修正

2021/12/01 08:43

投稿

taront
taront

スコア59

test CHANGED
@@ -5,12 +5,6 @@
5
5
  ```
6
6
 
7
7
  import numpy as np
8
-
9
-
10
-
11
- # orbit = np.random.rand(100) # サイズが100の配列の乱数
12
-
13
- # print(orbit)
14
8
 
15
9
 
16
10
 
@@ -70,8 +64,6 @@
70
64
 
71
65
  print(len(results))
72
66
 
73
- # print(np.sum(results))
74
-
75
67
  print(results)
76
68
 
77
69
  ```