Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add zero value support for statistics.geometric_mean() #112540

Closed
Labels
stdlibStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancement
@milthorpe

Description

@milthorpe

Bug report

Bug description:

Theimplementation ofstatistics.geometric_mean using logarithms requires that all input values must be positive. However, a real geometric mean is defined for all sets ofnon-negative real values. The geo mean of any set of numbers containing zero is itself zero.

fromstatisticsimportgeometric_meangeometric_mean([1.0,2.0,0.0])Traceback (mostrecentcalllast):File"<stdin>",line1,in<module>File"/home/milthorpe/miniconda3/lib/python3.11/statistics.py",line489,ingeometric_meanraiseStatisticsError('geometric mean requires a non-empty dataset 'statistics.StatisticsError:geometricmeanrequiresanon-emptydatasetcontainingpositivenumbers

I believegeometric_mean should return 0 if any of the input values are zero. (It should continue to return aStatisticsError if any of the input values are negative.)

CPython versions tested on:

3.11

Operating systems tested on:

Linux

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancement

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp