<jupyter_start><jupyter_text>The numpy.random package![Numpy logo](https://numpy.org/doc/stable/_static/numpy_logo.png)  IntroductionThis report will general overview of the Numpy package but will focus on the numpy.random package.  1. What is numpy.NumPy is a library for the Python for sciencetific computing used for working with arrays. Adding support for large, multi-dimensional arrays and matrices, along with a large collection of high-level mathematical functions to operate on these arrays. NumPy arrays are stored at one continuous place in memory unlike lists, so processes can access and manipulate them very efficiently.The core functionality of NumPy is its "ndarray", for n-dimensional array, data structure.  2. Numpy vs List [1]  List:A List is a member of a collection which is ordered and changeable. Allowing duplicate members. Also contained in the collection is  Tuple, set and Dictionary. A single list may contain DataTypes like Integers, Strings, as well as Objects. Lists are mutable, and hence, they can be altered even after their creation.List in Python are ordered and have a definite count. The elements in a list are indexed according to a definite sequence and the indexing of a list is done with 0 being the first index. Each element in the list has its definite place in the list, which allows duplicating of elements in the list, with each element having its own distinct place and credibility.Note- Lists are a useful tool for preserving a sequence of data and further iterating over it.<jupyter_code>stringlist = ["kiwi","tomatoes","grapes","apple", "banana", "cherry"]
print(stringlist)
numberlist = [1,2,3,4,5]
print(numberlist)
mulitDimentional = [[1,2,3,4,5],[6,7,8,9,10]]
print(mulitDimentional)
print("list array position 0 ", mulitDimentional[0])
print("list array position 1 ", mulitDimentional[1])<jupyter_output>[[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]]
list array position 0  [1, 2, 3, 4, 5]
list array position 1  [6, 7, 8, 9, 10]<jupyter_text>Numpy:This libary in python is used to work with arrays. The difference between Numpy will aim to provide a array object that is up to 50 times faster that a Python list.This is because numpy arrays are stored at one continous place in memory unlike lists, so process can access and manipulate then very efficiently called locality.<jupyter_code>import numpy as np
intArr = np.array([1,2,3,4,5])
print(intArr)<jupyter_output>[1 2 3 4 5]<jupyter_text>Numpy has many functions that allow the mulipation of arrays. This report will concantrate on numpy. [2]Numpy operations Numpy special functions  Body. [5]  Exploring the quick start 1. Explain the overall purpose of the package.Pseudo Random : Random numbers in a computer are generated by anlogrithm This which really means that its not truly random.THe python random uses Random Sampling to produce psoudo random generation combining combinations of a BitGenerator and a Generator. Bit Generator: use to create sequences. Objects that generate random numbers. These are typically unsigned integer words filled with sequences of either 32 or 64 random bits. The BitGenerator has a limited set of responsibilities. It manages state and provides functions to produce random doubles and random unsigned 32- and 64-bit values.[2]Generator: Objects that transform sequences of random bits from a BitGenerator into sequences of numbers that follow a specific probability distribution (such as uniform, Normal or Binomial) within a specified interval.The Generator is the user-facing object that is nearly identical to RandomState. The canonical method to initialize a generator passes a PCG64 bit generator as the sole argument.[2]The random module Mersene Twister PRNG algorithm.[3]Methods of the random package includerand() : this is for floating point number returns floats  between 0 and 1 but not including 1.randInt()choice()  Simple random data<jupyter_code>#simple random float generator betewwn 0 and 1 
# but not including 1
rna = np.random.rand()
print(rna)
# 2nd simple random float generator 
# this returns a array of 5 random numbers between 0 and 1
# not including 1
rna = np.random.rand(5)
print(rna)

# 3rd 2d array of float numbers between 0 and 1 
# not including 1 with 4 coloums and 3 rows
rna = np.random.rand(3,4)
print(rna)<jupyter_output>[[0.19514199 0.15376298 0.79604361 0.1270199 ]
 [0.86195634 0.11563247 0.09944939 0.72201785]
 [0.13362743 0.42524592 0.9379632  0.52339309]]<jupyter_text>randInt()<jupyter_code># creates a randdom whole integer number 
# between 1 and 100 but does not include 100
rns = np.random.randint(100)
print(rns)
# creates a randdom whole integer number 
# between 1 and 100 but does not include 1000
rns = np.random.randint(1000)
print(rns)
# creates a 2d randdom whole integer number 
# between 1 and 100 but does not include 100
# this uses the size functon that gives 3 rows and 4 coloums
rns = np.random.randint(100, size=(3,4))
print(rns)<jupyter_output>[[59 92 56 58]
 [81 87 68 47]
 [24 25 72 75]]<jupyter_text>Choice()  this method will generate a random value based on a array of values.<jupyter_code># choice will pick a value from the passed array
rns = np.random.choice([3,5,6,2])
print(rns)
# 2d choice will return a randomly generated 2d array 
# based on the values passed
# of size 3 row and 4 columns 
rns = np.random.choice([3,5,6,2], size=(3,4))
print(rns)<jupyter_output>[[6 3 3 5]
 [6 6 5 3]
 [6 2 2 3]]<jupyter_text>Permutation Permutation the re-ordering of elements in a list.[4]<jupyter_code>#The permutation() method returns a re-arranged array 
#(and leaves the original array un-changed).
arr = np.array([1,2,3,4,5,6,7,8,9])
per = np.random.permutation(arr)
print(per)
# using random multidementional arrays and permuation to generate a 
# random mulitdementional array. should be some math calculation 
# to determine the actual psedo randomness of the generated array....??? 
print("Random arrary using choice")
rns = np.random.choice([3,5,6,2], size=(3,4))
print(rns)
print("The create random  arrray with permutation")
per = np.random.permutation(rns)
print(per)<jupyter_output>Random arrary using choice
[[6 3 6 6]
 [3 5 6 6]
 [5 5 3 6]]
The create random  arrray with permutation
[[3 5 6 6]
 [6 3 6 6]
 [5 5 3 6]]<jupyter_text>The use and purpose of at least five “Distributions” functions. In this section the investigation will focus on the five most common Distrubution, uniform, ???, ???, ??? and ???. Whar ia distribution ? Contionus? Discreet? The Probability density Function(PDF) is used to specify the probability of the random variable falling within a particular range of values, as opposed to taking on any one value. [5]   Uniform Distribution This is the simples distribution functions and is continuos. ![uniform Dist](https://res.cloudinary.com/dyd911kmh/image/upload/f_auto,q_auto:best/v1539784816/output_5_0_f453qp.png)Since any interval of numbers of equal width has an equal probability of being observed, the curve will be a rectangle. The height is set to f(x) = 1/(b−a).  This is because the constant height across the interval and 0 height elsewhere. Since the area under the curve must be equal to 1, the length of the interval determines the height of the curve. The following figure ?? shows a uniform distribution in interval (a,b). Notice since the area needs to be 1. The height is set to .<jupyter_code># import uniform distribution
import scipy.stats as ss
# Seaborn is a library that uses Matplotlib underneath to plot graphs. 
#It will be used to visualize random distributions.
import seaborn as sns
# random numbers from uniform distribution
#the distribution is constant between loc and loc + scale
#size = 10000 is number of random variates
du = ss.uniform.rvs(size=np.random.randint(1000), loc = 30, scale=20)
#
ax = sns.distplot(du,bins=100,kde=True,
                  color='skyblue',
                  hist_kws={"linewidth": 10,'alpha':1})
ax.set(xlabel='Uniform Distribution ', ylabel='Frequency')<jupyter_output><empty_output><jupyter_text>Normal DistributionKnown Gaussiam Distribution is a bell shaped curve this shows the mean and the standard deviation. The density curve is symmertical and curved around the mean Known everywhere in data Science.[6]For values less that 1 standard deviation away from the mean account of just over 68% of the set. While 2 standard deviations from the mean account of just over 95%. While 3 standard deviations account for just over 99&  ![normal dist](https://res.cloudinary.com/dyd911kmh/image/upload/f_auto,q_auto:best/v1539784816/output_15_0_jv4dw1.png) ![nornal dis Curve](https://res.cloudinary.com/dyd911kmh/image/upload/f_auto,q_auto:best/v1539784816/output_17_0_rlgbfo.png)https://www.datacamp.com/community/tutorials/probability-distributions-python<jupyter_code># generate random numbers from N(0,1)
# loc = mean
# size = number of random variates 
data_normal = ss.norm.rvs(size=10000,loc=0,scale=1)
# now plot
ax = sns.distplot(data_normal,
                  bins=100,
                  kde=True,
                  color='skyblue',
                  hist_kws={"linewidth": 15,'alpha':1})
ax.set(xlabel='Normal Distribution', ylabel='Frequency')<jupyter_output><empty_output><jupyter_text>Poisson DistributionUsed to model the number of times an event occurs. lambda = the event rate.mu = rate at which the event happens.k = the probability of observing  k events in a interval.. equation:.![Poisson Distribution](https://res.cloudinary.com/dyd911kmh/image/upload/f_auto,q_auto:best/v1539784818/output_39_0_knqrjh.png)lambda will tend to head towards inifinity ![typical PD](https://res.cloudinary.com/dyd911kmh/image/upload/f_auto,q_auto:best/v1539784818/output_41_0_p5kbdc.png)<jupyter_code>data_poisson = ss.poisson.rvs(mu=3,size=10000)
ax = sns.distplot(data_poisson,
                  bins=30,
                  #kde line Teue to add
                  kde=False,
                  color='skyblue',
                  hist_kws={"linewidth": 15,'alpha':1})
ax.set(xlabel='Poisson Distribution', ylabel='Frequency')<jupyter_output><empty_output><jupyter_text>Binomial DistributionA distribution true or false / success of failureParamenters are : n = total number of trails. p = probability of sucess or failureEquation:![binomail equaton](https://res.cloudinary.com/dyd911kmh/image/upload/f_auto,q_auto:best/v1539784818/output_49_0_vajze8.png)Generation of discrete random variables<jupyter_code>data_binom = ss.binom.rvs(n=10, p=0.8,size=10000)
ax = sns.distplot(data_binom,
                  kde=False,
                  color='skyblue',
                  hist_kws={"linewidth": 15,'alpha':1})
ax.set(xlabel='Binomial Distribution', ylabel='Frequency')<jupyter_output><empty_output><jupyter_text>Probability of success was greater than 0.5 the distribution is skewed towards the right side. Also, poisson distribution is a limiting case of a binomial distribution under the following conditions:The number of trials is indefinitely large or n→∞.The probability of success for each trial is same and indefinitely small or p→0.np=λ, is finite.Normal distribution is another limiting form of binomial distribution under the following conditions:The number of trials is indefinitely large, n→∞.Both p and q are not indefinitely small.[6]  Bernoulli distributionThis distribution could be call a binary distribution, because there is only 2 possible outcomes 1 for success and 0 for failure.X = can have the value 1 and p or 1 - pP = the probability of success 1 - p = the probability of failure n = nnumber of trailsIn Bernoulli the n = 1Probability mass function is :![PMF](https://res.cloudinary.com/dyd911kmh/image/upload/f_auto,q_auto:best/v1539784819/output_56_0_w8z8gb.png)<jupyter_code>data_bern = ss.bernoulli.rvs(size=10000,p=0.6)

#visualise the data
ax= sns.distplot(data_bern,
                 kde=False,
                 color="skyblue",
                 hist_kws={"linewidth": 15,'alpha':1})
ax.set(xlabel='Bernoulli Distribution', ylabel='Frequency')<jupyter_output><empty_output><jupyter_text>The use of seeds in generating pseudorandom numbers THe function takes an integer value. When using this function in random libary. Seeding the a random generator will produce the same results. This is useful when running dev, test and production tests repateability.<jupyter_code>np.random.seed(0)
rns = np.random.randint(1000)
print(rns)
np.random.seed(0)
rns = np.random.randint(1000)
print(rns)
np.random.seed(0)
rns = np.random.randint(1000)
print(rns)
np.random.seed(0)
rns = np.random.randint(1000)
print(rns)
rng = np.random.default_rng()
vals = rng.standard_normal(10)
more_vals = rng.standard_normal(10)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.08428030303030302, 'fraction_numerical': 0.044744318181818184, 'mean_word_length': 4.765696087352138, 'pattern_counts': {'":': 5, '<': 43, '<?xml version=': 0, '>': 43, 'https://': 9, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '12', 'dir': 'jupyter-structured-clean-dedup', 'id': '516518', 'license': 'MIT', 'n_tokens_mistral': 4181, 'n_tokens_neox': 3720, 'n_words': 1488, 'path': 'numpy-random.ipynb', 'repo_name': 'G00387859/programming-for-data-analysis-assignment', 'size': '12672'}