How do I get numpy to generate two mean values?
up vote
-2
down vote
favorite
I have been asked to write a function to calculate the mean by reading in a CSV file using numpy. This is as far as I could get after playing with it for 4 hours.
import numpy as np
def calc_stats(data):
data = np.loadtxt("data.csv", delimiter=",")
mean = np.mean(data)
rounded = np.around(mean, decimals=1)
return rounded
The auto-grader tells me that my output is incorrect as shown below.
Testing the data.csv file from the example. We called your function like this:
>>> calc_stats('data.csv')
Your function returned:
11.095833333333333
when it was meant to return:
(11.1, 11.4)
(11.1, 11.4)
I read the numpy manual on the mean function and I did not find the information I am looking for.
python-3.x numpy
add a comment |
up vote
-2
down vote
favorite
I have been asked to write a function to calculate the mean by reading in a CSV file using numpy. This is as far as I could get after playing with it for 4 hours.
import numpy as np
def calc_stats(data):
data = np.loadtxt("data.csv", delimiter=",")
mean = np.mean(data)
rounded = np.around(mean, decimals=1)
return rounded
The auto-grader tells me that my output is incorrect as shown below.
Testing the data.csv file from the example. We called your function like this:
>>> calc_stats('data.csv')
Your function returned:
11.095833333333333
when it was meant to return:
(11.1, 11.4)
(11.1, 11.4)
I read the numpy manual on the mean function and I did not find the information I am looking for.
python-3.x numpy
Have you checked the examples in the docs? The first one without an axis argument, the second and the third ones with an axis argument?
– ayhan
Nov 9 at 6:18
yes I checked. I can't get the code to output(11.1, 11.4)
– Alok Y
Nov 9 at 6:32
As there appears to be more than one answer, I'm guessing you have two fields on each line, separated by a comma, and you should maybe total each column of values...
– Mark Setchell
Nov 9 at 7:47
add a comment |
up vote
-2
down vote
favorite
up vote
-2
down vote
favorite
I have been asked to write a function to calculate the mean by reading in a CSV file using numpy. This is as far as I could get after playing with it for 4 hours.
import numpy as np
def calc_stats(data):
data = np.loadtxt("data.csv", delimiter=",")
mean = np.mean(data)
rounded = np.around(mean, decimals=1)
return rounded
The auto-grader tells me that my output is incorrect as shown below.
Testing the data.csv file from the example. We called your function like this:
>>> calc_stats('data.csv')
Your function returned:
11.095833333333333
when it was meant to return:
(11.1, 11.4)
(11.1, 11.4)
I read the numpy manual on the mean function and I did not find the information I am looking for.
python-3.x numpy
I have been asked to write a function to calculate the mean by reading in a CSV file using numpy. This is as far as I could get after playing with it for 4 hours.
import numpy as np
def calc_stats(data):
data = np.loadtxt("data.csv", delimiter=",")
mean = np.mean(data)
rounded = np.around(mean, decimals=1)
return rounded
The auto-grader tells me that my output is incorrect as shown below.
Testing the data.csv file from the example. We called your function like this:
>>> calc_stats('data.csv')
Your function returned:
11.095833333333333
when it was meant to return:
(11.1, 11.4)
(11.1, 11.4)
I read the numpy manual on the mean function and I did not find the information I am looking for.
python-3.x numpy
python-3.x numpy
edited 2 days ago
Omid Nikrah
1,6291520
1,6291520
asked Nov 9 at 3:41
Alok Y
145
145
Have you checked the examples in the docs? The first one without an axis argument, the second and the third ones with an axis argument?
– ayhan
Nov 9 at 6:18
yes I checked. I can't get the code to output(11.1, 11.4)
– Alok Y
Nov 9 at 6:32
As there appears to be more than one answer, I'm guessing you have two fields on each line, separated by a comma, and you should maybe total each column of values...
– Mark Setchell
Nov 9 at 7:47
add a comment |
Have you checked the examples in the docs? The first one without an axis argument, the second and the third ones with an axis argument?
– ayhan
Nov 9 at 6:18
yes I checked. I can't get the code to output(11.1, 11.4)
– Alok Y
Nov 9 at 6:32
As there appears to be more than one answer, I'm guessing you have two fields on each line, separated by a comma, and you should maybe total each column of values...
– Mark Setchell
Nov 9 at 7:47
Have you checked the examples in the docs? The first one without an axis argument, the second and the third ones with an axis argument?
– ayhan
Nov 9 at 6:18
Have you checked the examples in the docs? The first one without an axis argument, the second and the third ones with an axis argument?
– ayhan
Nov 9 at 6:18
yes I checked. I can't get the code to output
(11.1, 11.4)– Alok Y
Nov 9 at 6:32
yes I checked. I can't get the code to output
(11.1, 11.4)– Alok Y
Nov 9 at 6:32
As there appears to be more than one answer, I'm guessing you have two fields on each line, separated by a comma, and you should maybe total each column of values...
– Mark Setchell
Nov 9 at 7:47
As there appears to be more than one answer, I'm guessing you have two fields on each line, separated by a comma, and you should maybe total each column of values...
– Mark Setchell
Nov 9 at 7:47
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53219533%2fhow-do-i-get-numpy-to-generate-two-mean-values%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Have you checked the examples in the docs? The first one without an axis argument, the second and the third ones with an axis argument?
– ayhan
Nov 9 at 6:18
yes I checked. I can't get the code to output
(11.1, 11.4)– Alok Y
Nov 9 at 6:32
As there appears to be more than one answer, I'm guessing you have two fields on each line, separated by a comma, and you should maybe total each column of values...
– Mark Setchell
Nov 9 at 7:47