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 14461
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 thread-safe 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/small-accidents-mean-big-trouble-for-supercollider.html
Small Accidents Mean Big Trouble for Supercollider
Image
Scientists expect startup...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
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 column-wise 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...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |