₦airaland Forum

Welcome, Guest: RegisterLoginWith GoogleTrendingRecentNew

Stats: 3,325,249 members, 8,420,969 topics. Date: Friday, 05 June 2026 at 03:29 PM

Toggle theme

Please Help With This Python Code - Programming - Nairaland

Nairaland ForumScience/TechnologyProgrammingPlease Help With This Python Code (2497 Views)

1 Reply (Go Down)

Please Help With This Python Code by cyrielo(op):
from math import sqrt

[color=#59718c]def [/color]zscore(obs, pop):
# Size of population.
number = float(len(pop))
# Average population value.
avg = sum(pop) / number
# Standard deviation of population.
std = sqrt(sum(((c - avg) ** 2) for c in pop) / number)
# Zscore Calculation.
return (obs - avg) / std

Am not a python developer, am php but this code looks pretty self explanatory, the confusing part is the double ** what does this mean in python, I need to implement this function in php, thanks guys
Re: Please Help With This Python Code by loomer: 6:22pm On Apr 27, 2015
Anaconda
Re: Please Help With This Python Code by Nobody: 6:40pm On Apr 27, 2015
na cobra code i know.
Re: Please Help With This Python Code by cyrielo(op): 6:43pm On Apr 27, 2015
when the function is called this is the output

==>>zscore(12, [2, 4, 4, 4, 5, 5, 7, 9] )

==>>3.5
Re: Please Help With This Python Code by kurtisblue:
cyrielo:
the confusing part is the [b]double ** [/b]what does this mean in python, I need to implement this function in php, thanks guys
It means power of
BTW y use float for population?
Re: Please Help With This Python Code by Aybee92(m): 9:01pm On Apr 27, 2015
d double ** means power e.g 4**3 is same as 4^3
Re: Please Help With This Python Code by sisqology(m): 9:02pm On Apr 27, 2015
Raise to power
Re: Please Help With This Python Code by cyrielo(op): 9:33pm On Apr 27, 2015
Thanks guys cool
Re: Please Help With This Python Code by kudaisi(m): 1:55pm On Apr 28, 2015
Also bear in Mind that ** when being used with a function argument it will have entirely different meaning in variance to power function it performs in this example. So if you see a code like this
def foo(arg1, ** arg2):
#some code here
The above does note mean arg1 raised to the power of arg2
Re: Please Help With This Python Code by sisqology(m):
kudaisi:
Also bear in Mind that ** when being used with a function argument it will have entirely different meaning in variance to power function it performs in this example. So if you see a code like this
def foo(arg1, ** arg2):
#some code here
The above does note mean arg1 raised to the power of arg2
def foo(*args, **kwargs):
#some code





undecided
Re: Please Help With This Python Code by kudaisi(m): 2:02am On Apr 29, 2015
sisqology:
def foo(*args, **kwargs):
#some code
undecided
Did I miss something ? If you mean to refer to '*args, **kwargs' it just a common idiom used in such scenarios. It can be changed with any variable name you please as long as it does not interfere with the inbuilt Python keywords.
Re: Please Help With This Python Code by sisqology(m): 9:03am On Apr 29, 2015
kudaisi:
Did I miss something ? If you mean to refer to '*args, **kwargs' it just a common idiom used in such scenarios. It can be changed with any variable name you please as long as it does not interfere with the inbuilt Python keywords.
No bro, I was only talking about another aspect where u can see **
Re: Please Help With This Python Code by kudaisi(m): 9:43am On Apr 29, 2015
sisqology:
No bro, I was only talking about another aspect where u can see **
Oh!..okay. Cool.
Re: Please Help With This Python Code by babatope88(m): 11:29am On Apr 29, 2015
You can do something like this as of

<?php
//php >=5.6.0

$power = $num**$base is accepted
//With old there is php built in power function


pow($num, $base);
Re: Please Help With This Python Code by spoilerx: 9:57am On May 01, 2015
cyrielo:
from math import sqrt

[color=#59718c]def [/color]zscore(obs, pop):
# Size of population.
number = float(len(pop))
# Average population value.
avg = sum(pop) / number
# Standard deviation of population.
std = sqrt(sum(((c - avg) ** 2) for c in pop) / number)
# Zscore Calculation.
return (obs - avg) / std

Am not a python developer, am php but this code looks pretty self explanatory, the confusing part is the double ** what does this mean in python, I need to implement this function in php, thanks guys
you didn't define the variable c
Re: Please Help With This Python Code by tr3y(m): 8:27pm On Apr 21, 2016
cyrielo:
Am not a python developer, am php but this code looks pretty self explanatory, the confusing part is the double ** what does this mean in python, I need to implement this function in php, thanks guys
Your email has issues, anything I can help you with?
Re: Please Help With This Python Code by cyrielo(op): 9:19pm On Apr 21, 2016
tr3y:
Your email has issues, anything I can help you with?
Yeah, how did it go with andela. im in the same scenario as you
Re: Please Help With This Python Code by tr3y(m): 12:01am On Apr 22, 2016
cyrielo:
Yeah, how did it go with andela. im in the same scenario as you
I went there for my interview and my name was actually on the list they had so I didn't bother to ask why they sent the regret mail
Re: Please Help With This Python Code by cyrielo(op): 12:52am On Apr 22, 2016
tr3y:
I went there for my interview and my name was actually on the list they had so I didn't bother to ask why they sent the regret mail
oh nice
Re: Please Help With This Python Code by tr3y(m): 12:06pm On Apr 22, 2016
cyrielo:
oh nice
Did you get any interview message from U-CONNECT?
Re: Please Help With This Python Code by cyrielo(op): 1:51pm On Apr 22, 2016
tr3y:
Did you get any interview message from U-CONNECT?
what is U-CONNECT?
1 Reply

Check Out My Python Code For Giving You The Date/time You Are Currently.I Need HELP With This Python ProblemPython Code For Birthday Reminder234

I Need Help With Pointers In CFemale Programmers Lets Meet HereAuto Respond Message By Using Gmail Smtp For Form Submit