When I added unpack_buffer_archive, in code review people said
it was redundant with unpack_buffer and they should be merged.
I said merging was too annoying. They were right. This merges
the functions together into a function with a 38 line docstring
and a 18 line implementation.
Merge together unpack_buffer and unpack_buffer_archive. When I added unpack_buffer_archive, in code review people said
it was redundant with unpack_buffer and they should be merged.
I said merging was too annoying. They were right. This merges
the functions together into a function with a 38 line docstring
and a 18 line implementation.
# http://stackoverflow.com/questions/20799403/improving-performance-of-cronbach-alpha-code-python-numpy
# pythran export cronbach(float [][])
# setup: import numpy as np ; N = 600 ; items = np.random.rand(N,N)
# run: cronbach(items)


def cronbach(itemscores):
    itemvars = itemscores.var(axis=1, ddof=1)
    tscores = itemscores.sum(axis=0)
    nitems = len(itemscores)
    return nitems / (nitems - 1) * (1 - itemvars.sum() / tscores.var(ddof=1))

# http://stackoverflow.com/questions/20799403/improving-performance-of-cronbach-alpha-code-python-numpy
# pythran export cronbach(float [][])
# setup: import numpy as np ; N = 600 ; items = np.random.rand(N,N)
# run: cronbach(items)


def cronbach(itemscores):
    itemvars = itemscores.var(axis=1, ddof=1)
    tscores = itemscores.sum(axis=0)
    nitems = len(itemscores)
    return nitems / (nitems - 1) * (1 - itemvars.sum() / tscores.var(ddof=1))
