mindspore.ops.dot

mindspore.ops.dot(input, other)[source]

Computation a dot product between samples in two tensors.

Parameters
  • input (Tensor) – First tensor in Dot op with datatype float16 or float32. The rank must be greater than or equal to 2.

  • other (Tensor) – Second tensor in Dot op with datatype float16 or float32. The rank must be greater than or equal to 2.

Returns

Tensor, dot product of input and other.

Raises
  • TypeError – If type of input and other are not the same.

  • TypeError – If dtype of input or other is not float16 or float32.

  • ValueError – If rank of input or other less than 2.

Supported Platforms:

Ascend GPU CPU

Examples

>>> import numpy as np
>>> import mindspore
>>> from mindspore import Tensor, ops
>>> input = Tensor(np.ones(shape=[2, 3]), mindspore.float32)
>>> other = Tensor(np.ones(shape=[1, 3, 2]), mindspore.float32)
>>> output = ops.dot(input, other)
>>> print(output)
[[[3. 3.]]
 [[3. 3.]]]
>>> print(output.shape)
(2, 1, 2)
>>> input = Tensor(np.ones(shape=[1, 2, 3]), mindspore.float32)
>>> other = Tensor(np.ones(shape=[1, 3, 2]), mindspore.float32)
>>> output = ops.dot(input, other)
>>> print(output)
[[[[3. 3.]]
  [[3. 3.]]]]
>>> print(output.shape)
(1, 2, 1, 2)
>>> input = Tensor(np.ones(shape=[1, 2, 3]), mindspore.float32)
>>> other = Tensor(np.ones(shape=[2, 3, 2]), mindspore.float32)
>>> output = ops.dot(input, other)
>>> print(output)
[[[[3. 3.]
   [3. 3.]]
  [[3. 3.]
   [3. 3.]]]]
>>> print(output.shape)
(1, 2, 2, 2)
>>> input = Tensor(np.ones(shape=[3, 2, 3]), mindspore.float32)
>>> other = Tensor(np.ones(shape=[2, 1, 3, 2]), mindspore.float32)
>>> output = ops.dot(input, other)
>>> print(output)
[[[[[3. 3.]]
   [[3. 3.]]]
  [[[3. 3.]]
   [[3. 3.]]]]
 [[[[3. 3.]]
   [[3. 3.]]]
  [[[3. 3.]]
   [[3. 3.]]]]
 [[[[3. 3.]]
   [[3. 3.]]]
  [[[3. 3.]]
   [[3. 3.]]]]]
>>> print(output.shape)
(3, 2, 2, 1, 2)