MCPcopy
hub / github.com/pandas-dev/pandas / dot

Method dot

pandas/core/series.py:2966–3044  ·  view source on GitHub ↗

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 us

(self, other: AnyArrayLike | DataFrame)

Source from the content-addressed store, hash-verified

2964 return self.corr(cast(Series, self.shift(lag)))
2965
2966 def dot(self, other: AnyArrayLike | DataFrame) -> Series | np.ndarray:
2967 """
2968 Compute the dot product between the Series and the columns of other.
2969
2970 This method computes the dot product between the Series and another
2971 one, or the Series and each columns of a DataFrame, or the Series and
2972 each columns of an array.
2973
2974 It can also be called using `self @ other`.
2975
2976 Parameters
2977 ----------
2978 other : Series, DataFrame or array-like
2979 The other object to compute the dot product with its columns.
2980
2981 Returns
2982 -------
2983 scalar, Series or numpy.ndarray
2984 Return the dot product of the Series and other if other is a
2985 Series, the Series of the dot product of Series and each rows of
2986 other if other is a DataFrame or a numpy.ndarray between the Series
2987 and each columns of the numpy array.
2988
2989 See Also
2990 --------
2991 DataFrame.dot: Compute the matrix product with the DataFrame.
2992 Series.mul: Multiplication of series and other, element-wise.
2993
2994 Notes
2995 -----
2996 The Series and other has to share the same index if other is a Series
2997 or a DataFrame.
2998
2999 Examples
3000 --------
3001 >>> s = pd.Series([0, 1, 2, 3])
3002 >>> other = pd.Series([-1, 2, -3, 4])
3003 >>> s.dot(other)
3004 8
3005 >>> s @ other
3006 8
3007 >>> df = pd.DataFrame([[0, 1], [-2, 3], [4, -5], [6, 7]])
3008 >>> s.dot(df)
3009 0 24
3010 1 14
3011 dtype: int64
3012 >>> arr = np.array([[0, 1], [-2, 3], [4, -5], [6, 7]])
3013 >>> s.dot(arr)
3014 array([24, 14])
3015 """
3016 if isinstance(other, (Series, ABCDataFrame)):
3017 common = self.index.union(other.index)
3018 if len(common) > len(self.index) or len(common) > len(other.index):
3019 raise ValueError("matrices are not aligned")
3020
3021 left = self.reindex(index=common)
3022 right = other.reindex(index=common)
3023 lvals = left.values

Callers 15

__matmul__Method · 0.95
__rmatmul__Method · 0.95
test_matmulMethod · 0.95
test_arrow_dtype_seriesFunction · 0.95
time_frame_dotMethod · 0.45
time_series_dotMethod · 0.45
time_frame_series_dotMethod · 0.45
test_dotMethod · 0.45
test_dot_2d_ndarrayMethod · 0.45
test_dot_1d_ndarrayMethod · 0.45
test_dot_seriesMethod · 0.45

Calls 6

reindexMethod · 0.95
_constructorMethod · 0.95
find_common_typeFunction · 0.90
maybe_unbox_numpy_scalarFunction · 0.90
__finalize__Method · 0.80
unionMethod · 0.45

Tested by 15

test_matmulMethod · 0.76
test_arrow_dtype_seriesFunction · 0.76
test_dotMethod · 0.36
test_dot_2d_ndarrayMethod · 0.36
test_dot_1d_ndarrayMethod · 0.36
test_dot_seriesMethod · 0.36
test_dot_alignsMethod · 0.36
test_dot_misalignedMethod · 0.36
expectedMethod · 0.36