python - Using 'If' to run the loop again? -


I'm producing 2 arrays of random numbers from 3 to 3 (this is my x and y coordinate accordingly ). However, if I use a loop related to X and Y over my radius (which is 3) then what is the need to create a new set of numbers? If I take this loop to get it after my loop? import random N = 3x = zero (N, float) y = zero (N, float) in the range for i (0, n): x [ii] = Uniform (6) -3 y [ii] = uniform (6) -3 if (x [n] * 2 + y [n] ** 2) ** 0.5 & gt; 3:

thanks

Most random library modules have a regular interval [0,1] but to return a floating point number from the same distribution. To choose randomly from an equal distribution on the [a, b] interval, where B & gt; One, you can only multiply by ba , and then add a .

I'm not sure which modules you are importing in your example, so I give examples using standard random modules, as well as numpy.random

< Strong> random

  import random def rand_range (a, b): i + rand_range (-3, 3) for range i = in category i for a + Return random.uniform () * (b - a) x = [rand_range (-3, 3) I (3)]   

numpy.random

Nampee allows one to work for speed and clarity . Import as imported NP DP Rand_Angase (A, B, Size): a + np.random.random (size) * (B - A) x = rand_range (-3, Return to 3, (3)) y = rand_range (3, 3, (3))

Or, create a 2D array of 2 rows of 3 elements, and use unpacking

  x, y = Rand_range (-3, 3, (2, 3))   

Check the border

The criteria for having the points generated with x, y = (0, 0), 3 units of y to make sure something similar can do: x = [ ] y = [] for the range i (3): x i, yi = 3, 3 # while examining basically determined candidates, xi ** 2 + yi ** 2 & gt; 9: xi = rand_range (-3, 3) yi = rand_range (-3, 3) x.append (xi) y.append (yi)

Looking at the underlying random method one At the interval [0,1], these arrays should undergo all the following affirmations:

 For xi, yi in zip (x, y): xi ** 2 + yi ** Emphasis 2 & lt; = 9    

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -