mindspore.ops.inner

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

Returns the inner product of two tensors.

For 1-D tensors (without complex conjugation), returns the ordinary inner product of vectors.

For higher dimensions, returns a sum product over the last axis.

Note

If input or other is a Tensor scalar, mindspore.ops.inner() will be the same as mindspore.ops.mul() .

Parameters
  • input (Tensor) – First input.

  • other (Tensor) – Second input.

Returns

Tensor, the result of the inner product.

Raises

ValueError – If neither input nor other is scalar, and the last dimension of the two input tensors do not match.

Supported Platforms:

Ascend GPU CPU

Examples

>>> import mindspore as ms
>>> from mindspore import Tensor, ops
>>> from mindspore import dtype as mstype
>>> # case1: 2 1D tensors
>>> input = ms.Tensor([1, 2, 3], mstype.float32)
>>> y = ms.Tensor([4, 5, 6], mstype.float32)
>>> output = ops.inner(input, y)
>>> print(output)
32
>>> # case2: Tensor scalar and tensor
>>> input = ms.Tensor([[[1, 2, 3], [3, 2, 1]], [[4, 5, 6], [4, 5, 6]]], mstype.float32)
>>> y = ms.Tensor(2, mstype.float32)
>>> output = ops.inner(input, y)
>>> print(output)
[[[ 2.  4.  6.]
  [ 6.  4.  2.]]
 [[ 8. 10. 12.]
  [ 8. 10. 12.]]]
>>> # case3: Two tensors
>>> input = ms.Tensor([[[1, 2, 3], [3, 2, 1]], [[4, 5, 6], [4, 5, 6]]], mstype.float32)
>>> y = ms.Tensor([[2, 3, 4], [4, 3, 2]], mstype.float32)
>>> output = ops.inner(input, y)
>>> print(output)
[[[20. 16.]
  [16. 20.]]
 [[47. 43.]
  [47. 43.]]]