Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Behavior of statistics.mean
#4
(Jan-29-2024, 09:33 AM)Gribouillis Wrote:
(Jan-29-2024, 09:18 AM)cametan Wrote: This means, since Python 3.11, some "change" in Python causes its strange behavior.

Could this be the cause of the new behavior?
What's new in Python 3.11 Wrote:The statistics functions mean(), variance() and stdev() now consume iterators in one pass rather than converting them to a list first. This is twice as fast and can save substantial memory. (Contributed by Raymond Hettinger in gh-90415.)
See What's new in Python 3.11

Thanks. That could be the cause.
This seems a sort of pitfall. It might be safe to convert from the result of unfoldr to a list.

def baz():
    from statistics import mean
    def foo(x):
        i = int(input())
        return None if i == 0 else (i, x + 1)
    print(mean(list(unfoldr(foo, 0)))) # converting from unfold's iterable to list first, before passing it to statistics.mean
Anyway, thanks for your advice!
Reply


Messages In This Thread
Behavior of statistics.mean - by cametan - Jan-29-2024, 06:51 AM
RE: Behavior of statistics.mean - by cametan - Jan-29-2024, 09:18 AM
RE: Behavior of statistics.mean - by Gribouillis - Jan-29-2024, 09:33 AM
RE: Behavior of statistics.mean - by cametan - Jan-29-2024, 11:27 AM
RE: Behavior of statistics.mean - by DeaD_EyE - Jan-30-2024, 09:20 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Simple statistics with range function Pythonlearner2019 2 2,226 Nov-25-2019, 05:25 PM
Last Post: Pythonlearner2019

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020