# general_inner_product#

ivy.general_inner_product(a, b, n_modes=None, /, *, out=None)[source]#

Generalised inner products between tensors.

Takes the inner product between the last (respectively first) n_modes of a (respectively b)

Parameters:
• a (`Union`[`Array`, `NativeArray`]) – first input tensor.

• b (`Union`[`Array`, `NativeArray`]) – second input tensor.

• n_modes (`Optional`[`int`], default: `None`) – int, default is None. If None, the traditional inner product is returned (i.e. a float) otherwise, the product between the n_modes last modes of a and the n_modes first modes of b is returned. The resulting tensor’s order is len(a) - n_modes.

• out (`Optional`[`Array`], default: `None`) – Optional output array. If provided, the output array to store the result.

Return type:

`Array`

Returns:

The inner product of the input arrays.

Examples

With `ivy.Array` inputs:

```>>> a = ivy.array([1, 2, 3])
>>> b = ivy.array([4, 5, 6])
>>> result = ivy.general_inner_product(a, b, n_modes=1)
>>> print(result)
ivy.array(32)
```
```>>> a = ivy.array([1, 2])
>>> b = ivy.array([4, 5])
>>> result = ivy.general_inner_product(a, b)
>>> print(result)
ivy.array(14)
```
```>>> a = ivy.array([[1, 1], [1, 1]])
>>> b = ivy.array([[1, 2, 3, 4],[1, 1, 1, 1]])
>>> result = ivy.general_inner_product(a, b, n_modes=1)
>>> print(result)
ivy.array([[2, 3, 4, 5],
[2, 3, 4, 5]])
```
Array.general_inner_product(self, b, n_modes=None, /, *, out=None)[source]#

ivy.Array instance method variant of ivy.general_inner_product. This method simply wraps the function, and so the docstring for ivy.general_inner_product also applies to this method with minimal changes.

Parameters:
• self (`Union`[`Array`, `NativeArray`]) – first input tensor.

• b (`Union`[`Array`, `NativeArray`]) – second input tensor.

• n_modes (`Optional`[`int`], default: `None`) – int, default is None. If None, the traditional inner product is returned (i.e. a float) otherwise, the product between the n_modes last modes of a and the n_modes first modes of b is returned. The resulting tensor’s order is len(a) - n_modes.

• out (`Optional`[`Array`], default: `None`) – Optional output array. If provided, the output array to store the result.

Return type:

`Array`

Returns:

The inner product of the input arrays.

Examples

With `ivy.Array` inputs:

```>>> a = ivy.array([1, 2, 3])
>>> b = ivy.array([4, 5, 6])
>>> result = a.general_inner_product(b, n_modes=1)
>>> print(result)
ivy.array(32)
```
```>>> a = ivy.array([1, 2])
>>> b = ivy.array([4, 5])
>>> result = a.general_inner_product(b)
>>> print(result)
ivy.array(14)
```
```>>> a = ivy.array([[1, 1], [1, 1]])
>>> b = ivy.array([[1, 2, 3, 4],[1, 1, 1, 1]])
>>> result = a.general_inner_product(b, n_modes=1)
>>> print(result)
ivy.array([[2, 3, 4, 5],
[2, 3, 4, 5]])
```
Container.general_inner_product(self, x2, n_modes=None, /, *, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, out=None)[source]#

ivy.Container instance method variant of ivy.general_inner_product.

This method simply wraps the function, and so the docstring for ivy.general_inner_product also applies to this method with minimal changes.

Return type:

`Container`