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.










share|improve this question
























  • 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















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.










share|improve this question
























  • 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













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.










share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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


















  • 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

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















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






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















 

draft saved


draft discarded



















































 


draft saved


draft discarded














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





















































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







Popular posts from this blog

Landwehr

Reims

Schenkenzell