본문 바로가기
파이썬

파이썬 NumPy의 가중 표준 편차

by º기록 2020. 12. 13.
반응형

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

 

 

반응형

댓글