Re: [Tutor] Statistics with python

2018-10-15 Thread Mariam Haji
Hi,

I think this makes more sense to me to get the std. I will go with this
route since there is a number of age groups and not just 56.
Thanks guys for all your help.


>>> import numpy
>>> ages = [35, 45, 55, 70]
>>> numpy.mean(ages)
51.25
>>> numpy.std(ages)
12.93010054098575

On Sun, Oct 14, 2018 at 1:20 PM Oscar Benjamin 
wrote:

> I'm replying back to the tutor list. Can you reply there rather than
> directly to me please?
>
> Also I've moved your response below mine as that is the preferred
> style on this list. My answer is below.
>
> On Sun, 14 Oct 2018 at 16:05, Mariam Haji  wrote:
> >
> > On Sat, Oct 13, 2018 at 10:24 PM Oscar Benjamin <
> oscar.j.benja...@gmail.com> wrote:
> >>
> >> On Sat, 13 Oct 2018 at 11:23, Mariam Haji 
> wrote:
> >> >
> >> > Hi guys,
> >>
> >> Hi Mariam
> >>
> >> > the question is as:
> >> > If a sample of 50 patients is taken from a dataset what is the
> probability
> >> > that we will get a patient above the age of 56?
> >>
> >> I can think of several ways of interpreting this:
> >>
> >> (a): You have a dataset consisting of 50 patients. You want to know
> >> the probability that a patient chosen from that sample will be above
> >> the age of 56.
> >>
> >> (b): You have a dataset consisting of 50 patients. You consider it to
> >> be representative of a larger population of people. You would like to
> >> use your dataset to estimate the probability that a patient chosen
> >> from the larger population will be above the age of 56.
> >>
> >> (c): You have a larger dataset consisting of more than 50 patients.
> >> You want to know that probability that a sample of 50 patients chosen
> >> from the larger dataset will contain at least (or exactly?) one person
> >> above the age of 56.
> >>
> >> (d): You have a larger dataset, but you will only analyse a sample of
> >> 50 patients from it. You want to use statistics on that sample to
> >> estimate the probability that a patient chosen from the larger dataset
> >> will be above the age of 56.
> >>
> >> I can list more interpretations but I think it would be better to wait
> >> for you to clarify.
> >
> > My dataset consists of 300+ patients and I want to analyze analyse a
> sample of 50 patients from it.
> > Yto know the probability that a patient chosen from the larger dataset
> > will be above the age of 56.
>
> Is this a homework problem or an actual problem?
>
> If I had 300+ patients I would think that the best way to work out the
> probability that a patient chosen from those 300+ was over the age of
> 56 would be to count how many are over the age of 56. Likewise if I
> wanted to estimate how many would be over the age of 56 using a
> smaller sample of 50 patients then I would also just count how many
> are over the age of 56 in that smaller sample.
>
> I'm going to guess that this is a homework problem and that you have
> been asked to assume that the ages are normally distributed (which
> they would not be in reality).
>
> Your calculation for the standard deviation given in your earlier
> email doesn't make any sense. You should calculate this using a
> function that calculates the standard deviation. There is one in the
> numpy module:
>
> >>> import numpy
> >>> ages = [35, 45, 55, 70]
> >>> numpy.mean(ages)
> 51.25
> >>> numpy.std(ages)
> 12.93010054098575
>
> --
> Oscar
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>


-- 
*Regards,*
*Mariam.*
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] what does the forward slash mean in this function signature?

2018-10-15 Thread eryk sun
On Mon, Oct 15, 2018 at 6:00 AM Albert-Jan Roskam
 wrote:
>
> In Python 3.6 (Windows) I often see a forward slash in a function signature, 
> see below.
> What does it mean? I vaguely remember reading something about new 
> possbilities in
> python 3, something like "def foo(x, *, y)". Perhaps it's related to that?
>
> >>> help({}.fromkeys)
> Help on built-in function fromkeys:
>
> fromkeys(iterable, value=None, /) method of builtins.type instance
> Returns a new dict with keys from iterable and values equal to value.

This syntax is for position-only function parameters. It's used by
Argument Clinic [1], a preprocessor used internally to develop
CPython. Position-only parameters have also been proposed for the
language grammar, first in PEP 457 and again in PEP 570 [2].

[1]: https://docs.python.org/3/howto/clinic.html#converting-your-first-function
[2]: https://www.python.org/dev/peps/pep-0570
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] what does the forward slash mean in this function signature?

2018-10-15 Thread Albert-Jan Roskam
Hello,


In Python 3.6 (Windows) I often see a forward slash in a function signature, 
see below. What does it mean? I vaguely remember reading something about new 
possbilities in python 3, something like "def foo(x, *, y)". Perhaps it's 
related to that?


>>> help({}.fromkeys)
Help on built-in function fromkeys:

fromkeys(iterable, value=None, /) method of builtins.type instance
Returns a new dict with keys from iterable and values equal to value.


Thanks!


Albert-Jan
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] python game error

2018-10-15 Thread Peter Otten
Alan Gauld via Tutor wrote:

> On 15/10/18 08:57, Peter Otten wrote:
> 
>> By the way, you do not need a map (dict) at all to implement a game like
>> this, you may return the next scene directly. A sketch:
>> 
>> class Bridge:
>> def enter(self):
>> ...
>> action = ...
>> if action == "jump off the bridge":
>> return Death("You are eaten by the piranhas")
>> else:
>> ...
> 
> That was my initial thought when I saw this but thee is one
> caveat. The original design creates a single instance of a
> scene and returns that on each access. The suggestion above
> creates a new instance on every call. So if it is important
> to use the same instance each time then the map is a
> better solution.
> 
> (Although you could instead create a class variable holding
> the first instance of itself then use a class  constructor
> to either create the instance or access the class variable...)
> 

Or, to keep it really simple, return global class instances:

DEATH_BY_TORNADO = Death("The storm swept you off the bridge")

>> class Bridge:
>> def enter(self):
>> ...
>> action = ...
   if action == "tornado":
   return DEATH_BY_TORNADO

One advantage of both variants is that tools like pylint are likely to catch 
spelling errors like the one that prompted the initial question.

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] python game error

2018-10-15 Thread Alan Gauld via Tutor
On 15/10/18 08:57, Peter Otten wrote:

> By the way, you do not need a map (dict) at all to implement a game like 
> this, you may return the next scene directly. A sketch:
> 
> class Bridge:
> def enter(self):
> ...
> action = ...
> if action == "jump off the bridge":
> return Death("You are eaten by the piranhas")
> else:
> ...

That was my initial thought when I saw this but thee is one
caveat. The original design creates a single instance of a
scene and returns that on each access. The suggestion above
creates a new instance on every call. So if it is important
to use the same instance each time then the map is a
better solution.

(Although you could instead create a class variable holding
the first instance of itself then use a class  constructor
to either create the instance or access the class variable...)

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] python game error

2018-10-15 Thread Peter Otten
bob gailer wrote:


>  Python coding "trick"1  
> when I build a map I omit the () after the class e.g. 'death' = Death, 
> ... and apply them to the item retrieved from the map.
> 
> use a decorator to build the map dictionary:
> 
> # the decorator function:
> def add_to_map(cls, map={}): # map is initialized to a {} when function 
> is "compiled"
>  if cls:
>  map[cls.__name__] = cls # add entry to dictionary
>  return cls
>  else: return map
> 
> # apply decorator to class definitions
> # this will add 'Death': 
> @add_to_map
> class Death(Scene):
>  class_definition
> 
>   # ditto for all other classes based on Scene - then
> 
> class Map:
>  scenes  = add_to_map() # note when map is called with no arguments 
> it returns the dictionary

Hm, you have now replaced the dead simple

> class Map(object):
> scenes = {
> 'central_corridor': CentralCorridor(),
> 'laser_weapon_armory': LaserWeaponArmory(),
> 'the_bridge': TheBridge(),
> 'escape_pod': EscapePod(),
> 'death': Death()
> }

with a class decorator, a dunder name, a mutable default argument -- lots of 
clever Python specific stuff that I wouldn't put on a beginner's list of top 
priorities.

Don't use unless you spotted at least one bug in the code sample at first 
glance :)

By the way, you do not need a map (dict) at all to implement a game like 
this, you may return the next scene directly. A sketch:

class Bridge:
def enter(self):
...
action = ...
if action == "jump off the bridge":
return Death("You are eaten by the piranhas")
else:
...



___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor