Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9200973
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:53:35+00:00 2026-06-17T22:53:35+00:00

What I’m trying to do is make a gaussian function graph. then pick random

  • 0

What I’m trying to do is make a gaussian function graph. then pick random numbers anywhere in a space say y=[0,1] (because its normalized) & x=[0,200]. Then, I want it to ignore all values above the curve and only keep the values underneath it.

   import numpy
   import random
   import math
   import matplotlib.pyplot as plt
   import matplotlib.mlab as mlab
   from math import sqrt
   from numpy import zeros
   from numpy import numarray

   variance = input("Input variance of the star:")
   mean = input("Input mean of the star:")

   x=numpy.linspace(0,200,1000)
   sigma = sqrt(variance)

   z = max(mlab.normpdf(x,mean,sigma))
   foo = (mlab.normpdf(x,mean,sigma))/z
   plt.plot(x,foo)

   zing = random.random()
   random = random.uniform(0,200)

   import random

   def method2(size):
       ret = set()
       while len(ret) < size:
           ret.add((random.random(), random.uniform(0,200)))
       return ret

   size = input("Input number of simulations:")

   foos = set(foo)
   xx = set(x)

   method = method2(size)

   def undercurve(xx,foos,method):
       Upper = numpy.where(foos<(method))
       Lower = numpy.where(foos[Upper]>(method[Upper]))
       return (xx[Upper])[Lower],(foos[Upper])[Lower]

When I try to print undercurve, I get an error:

    TypeError: 'set' object has no attribute '__getitem__'

and I have no idea how to fix it.

As you can all see, I’m quite new at python and programming in general, but any help is appreciated and if there are any questions I’ll do my best to answer them.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T22:53:37+00:00Added an answer on June 17, 2026 at 10:53 pm

    The immediate cause of the error you’re seeing is presumably this line (which should be identified by the full traceback — it’s generally quite helpful to post that):

    Lower = numpy.where(foos[Upper]>(method[Upper]))
    

    because the confusingly-named variable method is actually a set, as returned by your function method2. Actually, on second thought, foos is also a set, so it’s probably failing on that first. Sets don’t support indexing with something like the_set[index]; that’s what the complaint about __getitem__ means.

    I’m not entirely sure what all the parts of your code are intended to do; variable names like “foos” don’t really help like that. So here’s how I might do what you’re trying to do:

    # generate sample points
    num_pts = 500
    sample_xs = np.random.uniform(0, 200, size=num_pts)
    sample_ys = np.random.uniform(0, 1, size=num_pts)
    
    # define distribution
    mean = 50
    sigma = 10
    
    # figure out "normalized" pdf vals at sample points
    max_pdf = mlab.normpdf(mean, mean, sigma)
    sample_pdf_vals = mlab.normpdf(sample_xs, mean, sigma) / max_pdf
    
    # which ones are under the curve?
    under_curve = sample_ys < sample_pdf_vals
    
    # get pdf vals to plot
    x = np.linspace(0, 200, 1000)
    pdf_vals = mlab.normpdf(x, mean, sigma) / max_pdf
    
    # plot the samples and the curve
    colors = np.array(['cyan' if b else 'red' for b in under_curve])
    scatter(sample_xs, sample_ys, c=colors)
    plot(x, pdf_vals)
    

    Of course, you should also realize that if you only want the points under the curve, this is equivalent to (but much less efficient than) just sampling from the normal distribution and then randomly selecting a y for each sample uniformly from 0 to the pdf value there:

    sample_xs = np.random.normal(mean, sigma, size=num_pts)
    max_pdf = mlab.normpdf(mean, mean, sigma)
    sample_pdf_vals = mlab.normpdf(sample_xs, mean, sigma) / max_pdf
    sample_ys = np.array([np.random.uniform(0, pdf_val) for pdf_val in sample_pdf_vals])
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to select an H1 element which is the second-child in its group
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.