My Book of Python Computing by Kar Gupta Abhijit & Kar Gupta Abhijit
Author:Kar Gupta, Abhijit & Kar Gupta, Abhijit [Kar Gupta, Abhijit]
Language: eng
Format: epub
Publisher: UNKNOWN
Published: 2021-04-25T16:00:00+00:00
The centroid is also shown at (2, 1.666 â¦). [The plotting can be done with Polygon(points) or with plot(x, y) function frommatplotlib.pyplot module.]
# Variance, Standard deviation, Peak-to-Peak
>>> x = np.array([0, 1, -1, 2, 3,
-2, 0.5, 1.5, 2.5])
>>> x.var()
2.388888888888889
>>> x.std()
1.5456030825826172
# Peak-to-Peak value: Highest - Lowest >>> x.ptp()
5.0
>>> X = x.reshape(3, 3)
>>> X
array([[ 0. , 1. , -1. ],
[ 2. , 3. , -2. ],
[ 0.5, 1.5, 2.5]])
>>> X.var(0) # Along axis = 0 array([0.72222222, 0.72222222, 3.72222222]) >>> X.var(1) # Along axis = 1 array([0.66666667, 4.66666667, 0.66666667])
>>> X.std(0)
array([0.84983659, 0.84983659,
1.92930615]) >>> X.std(1)
array([0.81649658, 2.1602469 ,
0.81649658])
>>> X.ptp(0)
array([2. , 2. , 4.5]) >>> X.ptp(1)
array([2., 5., 2.]) # Cov, Correlation Coefficient
>>> x = np.random.uniform(0, 1, 1000)
>>> y = np.random.uniform(0, 1, 1000)
# Covariant Matrix
>>> np.cov(x, y)
array([[0.08178297, 0.00351387], [0.00351387, 0.083107 ]])
# Correlation Coefficient Matrix >>> np.corrcoef(x, y)
array([[1., 0.04262211],
[0.04262211, 1. ]])
Note: Two sets of 1000 random data points are taken. Correlation and Covariance are seen among them. The Correlation Coefficient Matrix is calculated with Pearson product-moment correlation coefficients between two sets of data.
8.2.10 Product, Difference
>>> x = np.array([1, 2, -1, 3, -2])
# Product of elements >>> np.prod(x)
12
# Essentially, factorial of 5 >>> np.prod(range(1, 6)) 120
# Diff between successive elements >>> np.diff(x)
array([1, -3, 4, -5])
Note: The difference array can be obtained through slicing also.
>>> x = np.array([1, 2, -1, 3, -2])
>>> x[1:] - x[:-1]
array([ 1, -3, 4, -5])
Note: For multidimensional arrays, the axis reference in prod() ordiff() is similar to that of any other NumPy methods. The same is true for other methods like np.add() and no.divide() for addition and divisions. NumPy arrays are vectorized. Element wise mathematical operations between NumPy arrays can be done with mathematical operators like +, -, *, /, ** and so on. But the NumPy methods are particularly useful because we can give axis reference and manipulate through other keyword arguments.
Application:
Consider the following �� vs. �� data [A sigmoidal curve created through NumPy function and array, for demonstration.]. The first derivative, �� = ����/���� is computed through np.diff() .
# Python Script
x = np.linspace(-5, 5, 100) y = 1.0/(1 + np.exp(-x)) z = np.diff(y)/np.diff(x)
# For plotting
import matplotlib.pyplot as plt
plt.subplot(211) plt.plot(x, y)
plt.subplot(212)
plt.plot(x[:-1], z)
plt.show()
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Management Strategies for the Cloud Revolution: How Cloud Computing Is Transforming Business and Why You Can't Afford to Be Left Behind by Charles Babcock(4127)
Ego Is the Enemy by Ryan Holiday(3983)
Offensive Shellcode from Scratch by Rishalin Pillay(3622)
Exploring Deepfakes by Bryan Lyon and Matt Tora(3187)
Robo-Advisor with Python by Aki Ranin(2960)
Learning C# by Developing Games with Unity 2021 by Harrison Ferrone(2842)
Speed Up Your Python with Rust by Maxwell Flitton(2834)
Liar's Poker by Michael Lewis(2806)
Linux Command Line and Shell Scripting Techniques by Vedran Dakic and Jasmin Redzepagic(2786)
Agile Security Operations by Hinne Hettema(2783)
OPNsense Beginner to Professional by Julio Cesar Bueno de Camargo(2782)
Extreme DAX by Michiel Rozema & Henk Vlootman(2779)
Essential Cryptography for JavaScript Developers by Alessandro Segala(2721)
Elevating React Web Development with Gatsby by Samuel Larsen-Disney(2710)
AI-Powered Commerce by Andy Pandharikar & Frederik Bussler(2630)
Python for ArcGIS Pro by Silas Toms Bill Parker(2625)
Cryptography Algorithms by Massimo Bertaccini(2615)
Incident Response Techniques for Ransomware Attacks by Oleg Skulkin(2609)
Distributed .NET with Microsoft Orleans by Bhupesh Guptha Muthiyalu Suneel Kumar Kunani(2609)