{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

hw5_sol - /usr/bin/env python AST5765/4762 2009 HW5...

Info icon This preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
#! /usr/bin/env python # AST5765/4762 2009 HW5 Solutions # NOTE: This assignment uses Monte Carlo methods to generate datasets. # This means that you may get different numbers from those presented # here. In the elimination questions, you may eliminate all 4 bad # points right away, or have one that is within the data's range and # is never gotten rid of. Try running it more than once to get a # sense for how it behaves. import numpy as np import matplotlib.pyplot as plt import numpy.random # 1. N = 1000 #sigp = np.sqrt(N) # appropriate for Gaussian approximation of Poisson #cx = N # appropriate for Gaussian approximation of Poisson Nump = 396 psamp = np.random.poisson(N, Nump) ulo = 0. uhi = 1e5 Numu = 4 usamp = np.random.uniform(ulo, uhi, Numu) samp = np.concatenate((psamp, usamp)) print(samp.mean()) # 1324.9651346859694 smed = np.median(samp.flat) print(smed) # 1001.2992269540773, which is closer to N = 1000. # 2. sstd = samp.std() print(sstd) # 3710.6260786611542 subsamp = samp[np.where( np.abs((samp-smed)/sstd) < 5. )] print(subsamp.mean()) # 1036.69469997 print(np.median(subsamp.flat)) # 998.900218869 print(subsamp.std()) # 732.570353854 # Three points (in this run) have been removed. The median is still # accurate, the mean is more accurate than before, but the standard
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern