scipy stats.cosine () | python

scipy.stats.cosine () — it is a continuous cosine random variable that is defined by a standard format and some form parameters to complete its specification.

Parameters:
q: lower and upper tail probability
x: quantiles
loc: [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: Create cosine continuous random variable values ​​

from scipy.stats import cosine

numargs = cosine.numargs

[] = [ 0.6 ,] * numargs

rv = cosine ()

 

print ( "RV:" , rv)

Output:

 RV: & lt; scipy.stats._distn_infrastructure.rv_frozen object at 0x000001FDC89DEE10 & gt; 

Code # 2: cosine of random variables and probability distribution function.

import numpy as np

quantile = np .arange ( 0.01 , 1 , 0.1 )

  
# Random Variants

R = cosine.rvs (scale = 2 , size = 10 )

print ( "Random Variates:" , R)

 
# PDF

R = cosine.pdf (quantile, loc = 0 , scale = 1 )

print ( "Probability Distribution:" , R)

Exit:

 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.21989605 / p> 

import numpy as np

import matplotlib.pyplot as plt

  

distribution = np.linspace ( 0 , np.minimum (rv.dist.b, 5 ))

print ( "Distribution: " , 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: change location and scale

import matplotlib. pyplot as plt

import numpy as np

 

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

 
# Various positional arguments

y1 = cosine.pdf (x , 1 , 6 )

y2 = cosine. pdf (x, 1 , 4 )

plt.plot (x, y1, " * " , x, y2, " r-- " )