I need to define a function "geomean(numbers)" that takes all the numbers in the list, adds then together then takes the sum of the numbers and puts it to the power of 1/how many numbers there are in the list. the resulty should be something like this:
geomean([1,2,3,4])
1+2+3+4=10
10^(1/4)
do yall get what im trying to say? when i read what i just wrote its hard for ME to follow it.
if u look up geometrical mean on wikepedia you'll get a better understanding of what im trying to do.
4 14458
I need to define a function "geomean(numbers)" that takes all the numbers in the list, adds then together then takes the sum of the numbers and puts it to the power of 1/how many numbers there are in the list. the resulty should be something like this:
geomean([1,2,3,4])
1+2+3+4=10
10^(1/4)
do yall get what im trying to say? when i read what i just wrote its hard for ME to follow it.
if u look up geometrical mean on wikepedia you'll get a better understanding of what im trying to do.
Like this? 
def geomean(num_list):

return sum(num_list) ** (1.0/len(num_list))

I need to define a function "geomean(numbers)" that takes all the numbers in the list, adds then together then takes the sum of the numbers and puts it to the power of 1/how many numbers there are in the list. the resulty should be something like this:
geomean([1,2,3,4])
1+2+3+4=10
10^(1/4)
do yall get what im trying to say? when i read what i just wrote its hard for ME to follow it.
if u look up geometrical mean on wikepedia you'll get a better understanding of what im trying to do.
I hate to be a stickler on math, but the geometric mean of [1, 2, 3, 4] is (1*2*3*4)^(1/4)  def geomean(numbers):

product = 1

for n in numbers:

product *= n

return product ** (1.0/len(numbers))
bvdet 2,851
Expert Mod 2GB
I hate to be a stickler on math, but the geometric mean of [1, 2, 3, 4] is (1*2*3*4)^(1/4)  def geomean(numbers):

product = 1

for n in numbers:

product *= n

return product ** (1.0/len(numbers))
Good work KaezarRex. Here is the same calculation using reduce():  def geomean(nums):

return (reduce(lambda x, y: x*y, nums))**(1.0/len(nums))


nums = (1,2,3,4,5)

print geomean(nums)
>>> 2.6051710847
Good work KaezarRex. Here is the same calculation using reduce():  def geomean(nums):

return (reduce(lambda x, y: x*y, nums))**(1.0/len(nums))


nums = (1,2,3,4,5)

print geomean(nums)
>>> 2.6051710847
Nice! I knew there had to be a way to use reduce, but I have never used lambda before. Thanks for the example.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Roy Yao 
last post by:
Does it mean "(sizeof(int))* (p)" or "sizeof( (int)(*p) )" ?
According to my analysis, operator sizeof, (type) and * have the same
precedence, and they combine from right to left. Then this...

by: Steve Richter 
last post by:
What does the "." mean in the following sql script stmts?
use
GO
if exists (select * from dbo.sysobjects where
id = object_id(N'.')
and OBJECTPROPERTY(id,N'IsUserTable') = 1)
drop table ....

by: Protoman 
last post by:
I have a function that calculates the mean of the some numbers; I need
it to accept any number of parameters (one needs to be the number of
the other parameters) Can you help me out here? Here's...

by: Frank Rizzo 
last post by:
Some of the classes in the framework are marked as threadsafe in the
documentation. In particular the docs say the following:
"Any public static (*Shared* in Visual Basic) members of this type...

by: Crirus 
last post by:
There are some classes to reproduce geometrical shapes like circles or
squares? as there is rectangle

Cheers,
Crirus

If work were a good thing, the boss...

by: SpreadTooThin 
last post by:
import array
a = array.array('f', )
print a.mean()
print a.std_dev()
Is there a way to calculate the mean and standard deviation on array
data?
Do I need to import it into a Numeric Array...

by: prabu 
last post by:
Hi all,
I want to know, what does the value of the array in the following
statement mean and How to print the content of the array SMB_Negotiate
using printf?
unsigned char SMB_Negotiate =
...

by: king imran 
last post by:
I am giving u complete code. It works properly
But add max and mean functions so that it can work properly.
*
/LinkList.h/
*
#include "Node.h"
*
/* The LinkList class declaration*/
class**...

by: mrchatgroup 
last post by:
news from
http://www.mrchat.net/myblog/myblog/smallaccidentsmeanbigtroubleforsupercollider.html
Small Accidents Mean Big Trouble for Supercollider
Image
Scientists expect startup...

by: Faith0G 
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

by: isladogs 
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...

by: ryjfgjl 
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...

by: taylorcarr 
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...

by: aa123db 
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...

by: BarryA 
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...

by: nemocccc 
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

by: Sonnysonu 
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by columnwise with in the specific length.
suppose the i have to...

by: Hystou 
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
 