質問編集履歴

1

質問に必要なコード部分の記述漏れ

2021/04/20 12:36

投稿

200269km
200269km

スコア1

test CHANGED
File without changes
test CHANGED
@@ -92,32 +92,46 @@
92
92
 
93
93
  import numpy as np
94
94
 
95
+ import math
96
+
97
+ import numpy
98
+
95
99
  from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_DOWN
96
100
 
97
101
 
98
102
 
103
+
104
+
105
+ #math.sqrt(x)
106
+
107
+ #numpy.sqrt(array) 配列の要素の平方根
108
+
109
+ #https://www.mathpython.com/ja/python-number-ceil/
110
+
111
+ #数値の切り上げと切り下げ
112
+
113
+ def num_round(x):
114
+
115
+ if (x*10)%10 >= 5:
116
+
117
+ x = str(x)
118
+
119
+ x = Decimal(x).quantize(Decimal('0'), rounding=ROUND_HALF_UP)
120
+
121
+ else:
122
+
123
+ x = Decimal(x).quantize(Decimal('0'), rounding=ROUND_HALF_DOWN)
124
+
125
+ return x
126
+
127
+
128
+
99
129
  n = int(input())
100
130
 
101
131
  x = np.zeros(n)
102
132
 
103
133
  y = np.zeros(n)
104
134
 
105
-
106
-
107
- def make_round(var):
108
-
109
- if (var*10)%10 >= 5:
110
-
111
- var = Decimal(var).quantize(Decimal('0'), rounding=ROUND_HALF_UP)
112
-
113
- else:
114
-
115
- var = Decimal(var).quantize(Decimal('0'), rounding=ROUND_HALF_DOWN)
116
-
117
- return var
118
-
119
-
120
-
121
135
  for i in range(n):
122
136
 
123
137
  xi, yi = map(int, input().split())
@@ -128,33 +142,73 @@
128
142
 
129
143
 
130
144
 
145
+ aveX = int(sum(x)/n)
146
+
147
+ aveY = int(sum(y)/n)
148
+
131
- ### 身長の平均
149
+ #print(aveY)
132
-
150
+
151
+
152
+
153
+
154
+
133
- sumx = 0
155
+ aveX2 =0
134
-
156
+
135
- sumy = 0
157
+ aveY2 =0
158
+
159
+
136
160
 
137
161
  for i in range(n):
138
162
 
139
- sumx += x[i]
140
-
141
- sumy += y[i]
142
-
143
-
144
-
145
- avg_x = make_round(sumx/n)
163
+ aveX2 += (x[i] -aveX)*(x[i] -aveX)
146
-
147
-
148
-
149
- ### 体重の平均
164
+
150
-
151
- avg_y = make_round(sumy/n)
152
-
153
-
154
-
155
- print(avg_x)
165
+ #print(aveX2)
166
+
156
-
167
+ aveY2 += (y[i] -aveY)*(y[i] -aveY)
168
+
157
- print(avg_y)
169
+ #print(aveY2)
170
+
171
+
172
+
173
+ ### 重さの分散
174
+
175
+ var_x = aveX2/n
176
+
177
+ #print(var_x)
178
+
179
+ ### 重さの標準偏差
180
+
181
+ std_x = math.sqrt(var_x)
182
+
183
+
184
+
185
+ var_x = num_round(var_x)
186
+
187
+ std_x = num_round(std_x)
188
+
189
+ ### 糖度の分散
190
+
191
+ var_y = aveY2/n
192
+
193
+
194
+
195
+ ### 糖度の標準偏差
196
+
197
+ std_y = math.sqrt(var_y)
198
+
199
+
200
+
201
+ var_y = num_round(var_y)
202
+
203
+ std_y = num_round(std_y)
204
+
205
+
206
+
207
+
208
+
209
+ print(var_x, std_x)
210
+
211
+ print(var_y, std_y)
158
212
 
159
213
  ```
160
214