Skip to content

Performance of numpy average and numpy.mean function #5507

@skuschel

Description

@skuschel

I need a weightened average function on a VERY large Dataset (some 1e8 numbers or more). The numpy functions mean and average serve me well and fast, but I discovered, that numpy.average is slower than builing the weightened average myself with two numpy.mean functions, as shown by the example:
https://gist.github.com/skuschel/2d148a37a2ce17925fb0
np.average(a,weights=b) takes 0.32 sec on my computer, but
np.mean(a*b)/np.mean(b) takes 0.23 sec for the equally sized dataset, yielding the same result.
How does that make sense?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions