- Use
np.zerosto create an array with 10 elements, name itcounts. - Use a
forloop to create 100,000np.random.randintnumbers less than 10. Add 1.0 to each element ofcountsthat your random integer matches. (For instance, if your random number is 0, you would do counts[0] += 1.0. If your random number is 8, you would do counts[8] += 1.0.) - Create a new array
binswhere you divide each element incountsby 100,000. - Are all 10 spots in
binsthe same? Ifnp.random.randinttruly generated a "flat" random distribution, they should be. Perhaps they would look closer to 10% each if you did a bigger test. Try parts 1 through 3 again with more than 100,000 trials.
- Use
np.zerosto create an array with 10 elements, name itcounts. - Use a
forloop to create 100,000 random decimals between zero and one (userand). For each number you generate, multiple it by 10 and convert it to an integer usingint(). Then add your number to thecountsbin, as we did in part 2 of set 2. - Create a new array
binswhere you divide each element incountsby 100,000. - Are all 10 spots in
binsthe same? Ifnp.random.randtruly generated a "flat" random distribution, they should be. Perhaps they would look closer to 10% each if you did a bigger test. Try parts 1 through 3 again with more than trials.
Unlike randint and rand in Set 1, randn is not supposed to be flat. It is supposed to be a Normal Distribution.
- Use
zerosto create an array with 10 elements, name itcounts. - Use a
forloop to create 100,000 random decimals usingrandn. Take the absolute value (abs) of each of your numbers, then convert it to an integer usingint. If your number is less than 10, add 1.0 to the appropriate element in yourcountsarray, as in Sets 1 and 2 above. - Create a new array
binswhere you divide each element incountsby 100,000. - Take a look at
bins, does it match a Normal Distribution? Perhaps it would look closer to Normal if you did a bigger test. Try parts 1 through 3 again with more trials.
- Use
np.arangeto create an arrayawith values 0 to 99. - Use
np.random.shuffleto randomly re-ordera. - Randomly select an element from
ausingnp.random.choice. - Find the type of your selected element using
.dtype.