"S10 Day 0: Weighted Mean"의 두 판 사이의 차이

10번째 줄: 10번째 줄:
print(round((sum_X/sum(W)),1))
print(round((sum_X/sum(W)),1))
# 32.0
# 32.0
</source>
==R==
<source lang='r'>
a <- scan("stdin")
n <- a[1]
x <- a[2:(n+1)]
w <- a[(n+2):(2*n+1)]
cat( format( sum(x*w)/sum(w), nsmall=1) )
</source>
<source lang='r'>
lines <- readLines(file('stdin', open='r'))
x <- as.numeric(unlist(strsplit(lines[2],split=" ")))
w <- as.numeric(unlist(strsplit(lines[3],split=" ")))
cat( format(sum(x*w)/sum(w),nsmall=1) )
</source>
</source>


[[분류: 10 Days of Statistics]]
[[분류: 10 Days of Statistics]]

2018년 7월 28일 (토) 19:54 판

1 개요

2 Python

N = int(input())
X = list(map(int, input().split()))
W = list(map(int, input().split()))
sum_X = sum([a*b for a,b in zip(X,W)])
print(round((sum_X/sum(W)),1))
# 32.0

3 R

a <- scan("stdin")
n <- a[1]
x <- a[2:(n+1)]
w <- a[(n+2):(2*n+1)]
cat( format( sum(x*w)/sum(w), nsmall=1) )
lines <- readLines(file('stdin', open='r'))
x <- as.numeric(unlist(strsplit(lines[2],split=" ")))
w <- as.numeric(unlist(strsplit(lines[3],split=" ")))
cat( format(sum(x*w)/sum(w),nsmall=1) )
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}