FAQ: Statistical Distributions with NumPy - Standard Deviations and Normal Distribution, Part II

This community-built FAQ covers the “Standard Deviations and Normal Distribution, Part II” exercise from the lesson “Statistical Distributions with NumPy”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Data Science

Introduction to Statistics with NumPy

FAQs on the exercise Standard Deviations and Normal Distribution, Part II

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

Need a help with below things

Q. The average score on the SATs is 1000 and the standard deviation is 100.
2000 students took the exam. How many would you expect to have scores within the range of one_above and one_below ?

Save your response to the variable one_std and print it to the terminal.

My Code :

import numpy as np

one_above = 1000 + 100
one_below = 1000 -100

print(one_above, one_below)

one_std = np.random.normal(1000,100,2000)

expected_std= one_std[(one_std > one_below) | (one_std< one_above)]

count = 0

for x in expected_std :
count = count + 1
#print(one_std[(one_std > one_below) | (one_std< one_above)])
print(count)

Query : But I am getting count as 2000 which is wrong , please help with the correct logic

2 Likes

How to answer this question…
2000 students took the exam. How many would you expect to have scores within the range of one_above and one_below? i.e 1100-900…
I dont even know what is the mean or how many marks exam was it

i did:

one_std  = 2000 * 68 / 100

which equals to 1360, since the rules for normal distributions says:

  • 68% of our samples will fall between +/- 1 standard deviation of the mean.
    and in this exercise they asked for How many would you expect to have scores within the range of one_above and ‘one_below’ (range).
3 Likes

hi i liked the way you did it, its surly more complicated but you used some previous lessons.
i copied your code and it works fine if you change the | “or” to & “and” in line
expected_std= one_std[(one_std > one_below) | (one_std< one_above)]
i dont know why yet but it worked with me like that

one more note, you can use the len function instead of the count

1 Like

Hey guys, any idea why this calculation returned 0?

one_std = 2000 * (68 / 100)

When I exclude the brackets, it returns 1360.

In Python 2, 68 / 100 is 0 since integer division always resulted in an integer. 0.68 is not an integer, and the closest integer once truncated is zero.

When the brackets were left off, the multiplication occurred first thus avoiding multiplication by zero.

In Python 3 this will no longer apply. All division results in a float.

This is in Python 3 though. It’s from one of the lessons on here

One suspects there is an old version of Python running behind the scenes. Could be an old version of NumPy, for that matter. See if you can get things to run as expected in your environment or an up to date sand box.

Going to the lesson in the OP link,

import numpy as np
print (np.__version__)

gives,

1.13.3

How recent or out of date is that version?

I don’t have an environment of my own yet, so I used the python terminal at Python Tryit Editor v1.0

and it came out as expected, 1360.

So that would suggest an out of date environment in the courseware. There should be a channel for you to communicate this information to the CC team, if you care to explore that avenue. Apart from basic diagnostics, there’s not much else we can do from here. Hope you can work around the existing setup. At least now you know to expect some quirks.

Noted, I’ll try and let em know. Thanks again, mtf!

Edit: Roy sorry haha didn’t see that

1 Like