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 14453
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: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM).
In this month's session, the creator of the excellent VBE...
|
by: MeoLessi9 |
last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
|
by: Aftab Ahmad |
last post by:
Hello Experts!
I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
|
by: Aftab Ahmad |
last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below.
Dim IE As Object
Set IE =...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: marcoviolo |
last post by:
Dear all,
I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
| |