IMO the best long-term solution is to make sure that the built-in stats 
module (https://docs.python.org/3/library/statistics.html) can be used. 
However, as explained in the ticket https://trac.sagemath.org/ticket/29662 
(and https://trac.sagemath.org/ticket/28234), there are bugs that prevent 
users from using it with some Sage types. 


On Saturday, February 12, 2022 at 7:28:43 PM UTC-8 wst...@gmail.com wrote:

> This happened in https://trac.sagemath.org/ticket/29662, as requested
> by kcrisman. I just looked at that
> ticket and added a comment about several additional examples where
> deprecating mean breaks things
> in subtle ways...
>
> On Sat, Feb 12, 2022 at 7:14 PM Samuel Lelievre
> <samuel....@gmail.com> wrote:
> >
> > Dear sage-devel,
> >
> > Taking averages is a common operation, and a `mean` function
> > such that `mean(xx)` returns `sum(xx) / len(xx)` regardless of
> > the type of objects in the iterable `xx` is extremely convenient.
> >
> > For instance, for a polygon whose vertices `uu` have coordinates
> > in a number field and are represented as vectors over that field,
> > `mean(uu)` finds the centre of that polygon. To center the polygon
> > at the origin, use `c = mean(uu)` and `vv = [u - c for u in uu]`.
> >
> > In Sage 9.5, using `mean` displays a warning:
> > ```
> > DeprecationWarning: sage.stats.basic_stats.mean is deprecated;
> > use numpy.mean or numpy.nanmean instead
> > ```
> > This is after #29662 was merged in SageMath 9.5.beta1.
> >
> > Alas, `numpy.mean` cannot find the mean of a list of vectors
> > over a number field.
> >
> > Of course, as a workaround, I can define
> >
> > def mean(xx):
> > r"""
> > Return the mean of this iterable.
> > """
> > return sum(xx) / len(xx)
> >
> > and place that in an `init.sage` file in my `~/.sage` folder.
> >
> > Having that built into Sage is so much more convenient though.
> > Can we have it back?
> >
> > Kind polygonal regards, --Samuel
> >
> > --
> > You received this message because you are subscribed to the Google 
> Groups "sage-devel" group.
> > To unsubscribe from this group and stop receiving emails from it, send 
> an email to sage-devel+...@googlegroups.com.
> > To view this discussion on the web visit 
> https://groups.google.com/d/msgid/sage-devel/60fe4b1c-db88-4caa-8d13-670b9b3edb79n%40googlegroups.com
> .
>
>
>
> -- 
> William (http://wstein.org)
>

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sage-devel/72970d04-877d-41bb-8af5-7dce382f887bn%40googlegroups.com.

Reply via email to