diff --git a/pandas/core/series.py b/pandas/core/series.py index a613b22ea9046..141d738d0c3bf 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -2080,16 +2080,53 @@ def autocorr(self, lag=1): def dot(self, other): """ - Matrix multiplication with DataFrame or inner-product with Series - objects. Can also be called using `self @ other` in Python >= 3.5. + Compute the dot product between the Series and the columns of other. + + This method computes the dot product between the Series and another + one, or the Series and each columns of a DataFrame, or the Series and + each columns of an array. + + It can also be called using `self @ other` in Python >= 3.5. Parameters ---------- - other : Series or DataFrame + other : Series, DataFrame or array-like + The other object to compute the dot product with its columns. Returns ------- - dot_product : scalar or Series + scalar, Series or numpy.ndarray + Return the dot product of the Series and other if other is a + Series, the Series of the dot product of Series and each rows of + other if other is a DataFrame or a numpy.ndarray between the Series + and each columns of the numpy array. + + See Also + -------- + DataFrame.dot: Compute the matrix product with the DataFrame. + Series.mul: Multiplication of series and other, element-wise. + + Notes + ----- + The Series and other has to share the same index if other is a Series + or a DataFrame. + + Examples + -------- + >>> s = pd.Series([0, 1, 2, 3]) + >>> other = pd.Series([-1, 2, -3, 4]) + >>> s.dot(other) + 8 + >>> s @ other + 8 + >>> df = pd.DataFrame([[0 ,1], [-2, 3], [4, -5], [6, 7]]) + >>> s.dot(df) + 0 24 + 1 14 + dtype: int64 + >>> arr = np.array([[0, 1], [-2, 3], [4, -5], [6, 7]]) + >>> s.dot(arr) + array([24, 14]) """ from pandas.core.frame import DataFrame if isinstance(other, (Series, DataFrame)):