Overview:
- In mathematics, a dot product of two sequences is given by:
x.y = Sum(x1.y1 + x2.y2+…+xnyn)
- A pandas Series is a one-dimensional sequence built using numpy.ndarray and bundled with numerous methods to perform computing and data analysis.
- The dot product of two pandas series objects can be computed using the Series.dot() method.
Example:
# Example program to perform dot product # between two pandas series objects import pandas as pds
# Create pandas.Series objects series1 = pds.Series([1, 0, 5]); series2 = pds.Series([2, 1, 2]);
# Obtain dot product of two pandas Series objects series3 = series1.dot(series2);
print("Series1:"); print(series1);
print("Series2:"); print(series2);
print("Dot product of Series1 and Series2"); print(series3); |
Output:
Series1: 0 1 1 0 2 5 dtype: int64 Series2: 0 2 1 1 2 2 dtype: int64 Dot product of Series1 and Series2 12 |