Ejemplo n.º 1
0
def test_gmean_weights():
    x = [2, 3, 5, 8]
    w = [1, 2, 3, 4]
    wgm1 = gmean(x, weights=w)
    wx = sum([[xi]*wi for (xi, wi) in zip(x, w)], [])
    wgm2 = gmean(wx)
    assert mpmath.almosteq(wgm1, wgm2)
Ejemplo n.º 2
0
def test_gmean_0_weight():
    x = [2, 3, 5, 8, 13, 21]
    w = [1, 3, 5, 0,  4,  0]
    wgm1 = gmean(x, weights=w)
    # Filter out points where the weight is 0.
    xx, ww = zip(*[(xi, wi) for (xi, wi) in zip(x, w) if wi != 0])
    wgm2 = gmean(xx, weights=ww)
    assert mpmath.almosteq(wgm1, wgm2)
Ejemplo n.º 3
0
def test_gmean_with_0():
    assert gmean([3, 1, 0, 9]) == 0
Ejemplo n.º 4
0
def test_gmean_weights_all_one():
    x = [3, 4, 5, 10]
    assert mpmath.almosteq(gmean(x, weights=[1]*len(x)),
                           gmean(x))
Ejemplo n.º 5
0
def test_gmean():
    assert mpmath.almosteq(gmean([3, 3**3, 3**5]), 27)