반응형
numpy.average ()
에는 가중치 옵션이 있지만 numpy.std ()
에는 없습니다. 누구든지 해결 방법에 대한 제안이 있습니까?
해결 방법
다음의 짧은 "수동 계산"은 어떻습니까?
def weighted_avg_and_std(values, weights):
"""
Return the weighted average and standard deviation.
values, weights -- Numpy ndarrays with the same shape.
"""
average = numpy.average(values, weights=weights)
# Fast and numerically precise:
variance = numpy.average((values-average)**2, weights=weights)
return (average, math.sqrt(variance))
참조 페이지 https://stackoverflow.com/questions/2413522
반응형
'파이썬' 카테고리의 다른 글
파이썬 URL에서 Python 객체로 XML 구문 분석 (0) | 2020.12.13 |
---|---|
파이썬 How to convert a timedelta object into a datetime object (0) | 2020.12.13 |
파이썬 Python string class like StringBuilder in C#? (0) | 2020.12.13 |
파이썬 Python의 생성기 함수에서 한 번에 하나의 값을 얻는 방법은 무엇입니까? (0) | 2020.12.13 |
파이썬 오류 발생시 자동으로 Python 디버거 시작 (0) | 2020.12.13 |
댓글