mindspore.ops.dot

mindspore.ops.dot(input, other)[源代码]

两个Tensor之间的点积。

参数:
  • input (Tensor) - 第一个输入的Tensor,数据类型为float16或float32,秩必须大于或等于2。

  • other (Tensor) - 第二个输入的Tensor,数据类型为float16或float32,秩必须大于或等于2。

返回:

Tensor, inputother 的点积。

异常:
  • TypeError - inputother 的数据类型不相同。

  • TypeError - inputother 的数据类型不是float16或float32。

  • ValueError - inputother 的秩小于2。

支持平台:

Ascend GPU CPU

样例:

>>> 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)