scipy stats.cosine() | Python (original) (raw)

Last Updated : 20 Mar, 2019

scipy.stats.cosine() is an cosine continuous random variable that is defined with a standard format and some shape parameters to complete its specification.

Parameters : q : lower and upper tail probabilityx : quantilesloc : [optional]location parameter. Default = 0 scale : [optional]scale parameter. Default = 1 size : [tuple of ints, optional] shape or random variates. moments : [optional] composed of letters [‘mvsk’]; 'm' = mean, 'v' = variance, 's' = Fisher's skew and 'k' = Fisher's kurtosis. (default = 'mv'). Results : cosine continuous random variable

Code #1 : Creating cosine continuous random variable

Python3 `

from scipy.stats import cosine numargs = cosine.numargs [] = [0.6, ] * numargs rv = cosine()

print ("RV : \n", rv)

`

Output :

RV :
<scipy.stats._distn_infrastructure.rv_frozen object at 0x000001FDC89DEE10>

Code #2 : cosine random variates and probability distribution function.

Python3 1== `

import numpy as np quantile = np.arange (0.01, 1, 0.1)

Random Variates

R = cosine.rvs(scale = 2, size = 10) print ("Random Variates : \n", R)

PDF

R = cosine.pdf(quantile, loc = 0, scale = 1) print ("\nProbability Distribution : \n", R)

`

Output:

Random Variates : [ 1.2323289 2.49938238 0.29072394 -1.10925673 0.55881836 1.70470811 1.29090489 2.64865261 4.32789346 0.14597439]

Probability Distribution : [0.31830193 0.31734797 0.3148134 0.31072354 0.30511926 0.29805655 0.28960598 0.27985198 0.26889203 0.25683561]

Code #3 : Graphical Representation.

Python3 `

import numpy as np import matplotlib.pyplot as plt

distribution = np.linspace(0, np.minimum(rv.dist.b, 5)) print("Distribution : \n", distribution)

plot = plt.plot(distribution, rv.pdf(distribution))

`

Output :

Distribution : [0. 0.06411414 0.12822827 0.19234241 0.25645654 0.32057068 0.38468481 0.44879895 0.51291309 0.57702722 0.64114136 0.70525549 0.76936963 0.83348377 0.8975979 0.96171204 1.02582617 1.08994031 1.15405444 1.21816858 1.28228272 1.34639685 1.41051099 1.47462512 1.53873926 1.60285339 1.66696753 1.73108167 1.7951958 1.85930994 1.92342407 1.98753821 2.05165235 2.11576648 2.17988062 2.24399475 2.30810889 2.37222302 2.43633716 2.5004513 2.56456543 2.62867957 2.6927937 2.75690784 2.82102197 2.88513611 2.94925025 3.01336438 3.07747852 3.14159265]

Code #4: Varying Location and Scale

Python3 1== `

import matplotlib.pyplot as plt import numpy as np

x = np.linspace(0, 5, 100)

Varying positional arguments

y1 = cosine.pdf(x, 1, 6) y2 = cosine.pdf(x, 1, 4) plt.plot(x, y1, "*", x, y2, "r--")

`