Simple statistics question

38 views
Skip to first unread message

Ingo Dahn

unread,
Feb 11, 2020, 12:04:42 PM2/11/20
to CoCalc
According to http://doc.sagemath.org/html/en/reference/stats/sage/stats/basic_stats.html
the following should work (and it used to):

data = [random() for i in [1 .. 20]]
std(data)

But it gives
AttributeError: 'float' object has no attribute 'sqrt'

Any hints?

Harald Schilly

unread,
Feb 11, 2020, 12:33:03 PM2/11/20
to Ingo Dahn, CoCalc
Well, I can't find that example, or a similar one. I don't know if this is a bug or it just happened to work.

However, you can create random vectors in Sage, then it all fits well together:

data = random_vector(RR, 20)
std(data)

Regards, Harald



--
CoCalc: Collaborative Calculation in the Cloud -- https://cocalc.com
---
You received this message because you are subscribed to the Google Groups "CoCalc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cocalc+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cocalc/b5e279fe-74d1-4e53-b61f-70e1b73510d8%40googlegroups.com.


--
Harald Schilly – CoCalc Consultant – SageMath, Inc.
https://cocalc.com

William Stein

unread,
Feb 11, 2020, 1:37:05 PM2/11/20
to Harald Schilly, Ingo Dahn, CoCalc, Frédéric Chapoton, Frédéric Chapoton
On Tue, Feb 11, 2020 at 9:33 AM Harald Schilly <h...@sagemath.com> wrote:
>
> Well, I can't find that example, or a similar one. I don't know if this is a bug or it just happened to work.

Ingo -- thanks for finding this. It is definitely a bug. It is a bug
that Frédéric Chapoton introduced into a recent version of Sage when
doing some automated cleanup of the source code:

https://github.com/sagemath/sage/commit/c946256d9a2dce49beaef6b28c6e36df9a0a2b4b#diff-d0fae2d422c3c6f113110121d9faa9a6R219

I've cc'd Frédéric so he can fix this.

I guess this is one of the drawbacks of automated style suggestion
software; it suggests changes that look good at first glance, but can
break code. Your example should be a doctest.

This is a workaround in the current version of Sage:

sage: std([RR(random()) for i in [1 .. 20]])
0.291469277800344

However, it is slower. Harald's suggestion to convert to a numpy
array would be faster.

In case anybody is curious all these basic stats functions were first
written by Andrew Hou (https://github.com/amhou) as a univ. of
Washington undergrad student project... They really do have value
because they work on any number types (e.g., symbolics, etc.).
> To view this discussion on the web visit https://groups.google.com/d/msgid/cocalc/CA%2BCu88QiKa%2B1tnaUvrfYgM6jzsZEzZ5gsQ6X25jPjvo%3DCFv8-Q%40mail.gmail.com.



--

Best Regards,
William Stein

CEO, SageMath, Inc.

Ingo Dahn

unread,
Feb 13, 2020, 4:31:14 PM2/13/20
to William Stein, Harald Schilly, CoCalc, Frédéric Chapoton, Frédéric Chapoton
I have another case of "float has no attribute...":

show(plot(factorial(x),(x,1,5)))

which used to work previously.

Samuel Lelièvre

unread,
Feb 21, 2020, 3:57:15 AM2/21/20
to CoCalc


Le jeudi 13 février 2020 22:31:14 UTC+1, Ingo Dahn a écrit :
I have another case of "float has no attribute...":

show(plot(factorial(x),(x,1,5)))

which used to work previously.

That one is solved at

- Sage Trac ticket 26749
  Let `factorial` accept float arguments

pending positive review and merging in the next Sage version.

A similar solution should work for `sqrt`.



Samuel Lelièvre

unread,
Feb 21, 2020, 7:21:04 PM2/21/20
to CoCalc
Note: this is fixed in

- Sage Trac ticket 29184
  fix for some basic stats function

which was merged in Sage 9.1.beta5,
see the release announcement from
less than an hour ago:


Samuel

2020-02-11 19:37:05 UTC+1, William Stein:

Ingo Dahn

unread,
Feb 22, 2020, 4:03:55 AM2/22/20
to Samuel Lelièvre, CoCalc
? It is still not working in Cocalc nor SageCell. Please, give a note when it does.

--
CoCalc: Collaborative Calculation in the Cloud -- https://cocalc.com
---
You received this message because you are subscribed to a topic in the Google Groups "CoCalc" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/cocalc/rblsUHwBXQc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to cocalc+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cocalc/0dbb34bd-5ef8-4655-8914-30bd507bfe85%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages