inner#
- ivy.inner(x1, x2, /, *, out=None)[source]#
Return the inner product of two vectors
x1
andx2
.- Parameters:
x1 (
Union
[Array
,NativeArray
]) – first one-dimensional input array of size N. Should have a numeric data type. a(N,) array_like First input vector. Input is flattened if not already 1-dimensional.x2 (
Union
[Array
,NativeArray
]) – second one-dimensional input array of size M. Should have a numeric data type. b(M,) array_like Second input vector. Input is flattened if not already 1-dimensional.out (
Optional
[Array
], default:None
) – optional output array, for writing the result to. It must have a shape that the inputs broadcast to.
- Return type:
- Returns:
ret – a two-dimensional array containing the inner product and whose shape is (N, M). The returned array must have a data type determined by Type Promotion Rules.
Both the description and the type hints above assumes an array input for
simplicity, but this function is *nestable, and therefore also accepts*
ivy.Container
instances in place of any of the arguments.
Examples
Matrices of identical shapes
>>> x = ivy.array([[1., 2.], [3., 4.]]) >>> y = ivy.array([[5., 6.], [7., 8.]]) >>> d = ivy.inner(x, y) >>> print(d) ivy.array([[17., 23.], [39., 53.]])
# Matrices of different shapes
>>> x = ivy.array([[1., 2.], [3., 4.], [5., 6.]]) >>> y = ivy.array([[5., 6.], [7., 8.]]) >>> d = ivy.inner(x, y) >>> print(d) ivy.array([[17., 23.], [39., 53.], [61., 83.]])
# 3D matrices
>>> x = ivy.array([[[1., 2.], [3., 4.]], ... [[5., 6.], [7., 8.]]]) >>> y = ivy.array([[[9., 10.], [11., 12.]], ... [[13., 14.], [15., 16.]]]) >>> d = ivy.inner(x, y) >>> print(d) ivy.array([[[[ 29., 35.], [ 41., 47.]], [[ 67., 81.], [ 95., 109.]]], [[[105., 127.], [149., 171.]], [[143., 173.], [203., 233.]]]])
- Array.inner(self, x2, /, *, out=None)[source]#
Return the inner product of two vectors
self
andx2
.- Parameters:
self (
Array
) – first one-dimensional input array of size N. Should have a numeric data type. a(N,) array_like First input vector. Input is flattened if not already 1-dimensional.x2 (
Union
[Array
,NativeArray
]) – second one-dimensional input array of size M. Should have a numeric data type. b(M,) array_like Second input vector. Input is flattened if not already 1-dimensional.out (
Optional
[Array
], default:None
) – optional output array, for writing the result to. It must have a shape that the inputs broadcast to.
- Return type:
Array
- Returns:
ret – a two-dimensional array containing the inner product and whose shape is (N, M). The returned array must have a data type determined by Type Promotion Rules.
Examples
Matrices of identical shapes >>> x = ivy.array([[1., 2.], [3., 4.]]) >>> y = ivy.array([[5., 6.], [7., 8.]]) >>> d = x.inner(y) >>> print(d) ivy.array([[17., 23.], [39., 53.]])
# Matrices of different shapes >>> x = ivy.array([[1., 2.], [3., 4.],[5., 6.]]) >>> y = ivy.array([[5., 6.], [7., 8.]]) >>> d = x.inner(y) >>> print(d) ivy.array([[17., 23.], [39., 53.], [61., 83.]])
# 3D matrices >>> x = ivy.array([[[1., 2.], [3., 4.]], … [[5., 6.], [7., 8.]]]) >>> y = ivy.array([[[9., 10.], [11., 12.]], … [[13., 14.], [15., 16.]]]) >>> d = x.inner(y) >>> print(d) ivy.array([[[[ 29., 35.], [ 41., 47.]],
[[ 67., 81.], [ 95., 109.]]],
- [[[105., 127.], [149., 171.]],
[[143., 173.], [203., 233.]]]])
- Container.inner(self, x2, /, *, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, out=None)[source]#
ivy.Container instance method variant of ivy.inner. This method simply wraps the function, and so the docstring for ivy.inner also applies to this method with minimal changes.
Return the inner product of two vectors
self
andx2
.- Parameters:
self (
Container
) – input container of size N. Should have a numeric data type. a(N,) array_like First input vector. Input is flattened if not already 1-dimensional.x2 (
Union
[Container
,Array
,NativeArray
]) – one-dimensional input array of size M. Should have a numeric data type. b(M,) array_like Second input vector. Input is flattened if not already 1-dimensional.key_chains (
Optional
[Union
[List
[str
],Dict
[str
,str
],Container
]], default:None
) – The key-chains to apply or not apply the method to. Default isNone
.to_apply (
Union
[bool
,Container
], default:True
) – If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default isTrue
.prune_unapplied (
Union
[bool
,Container
], default:False
) – Whether to prune key_chains for which the function was not applied. Default isFalse
.map_sequences (
Union
[bool
,Container
], default:False
) – Whether to also map method to sequences (lists, tuples). Default isFalse
.out (
Optional
[Container
], default:None
) – optional output array, for writing the result to. It must have a shape that the inputs broadcast to.
- Return type:
Container
- Returns:
ret – a new container representing the inner product and whose shape is (N, M). The returned array must have a data type determined by Type Promotion Rules.
Examples
>>> x1 = ivy.Container(a=ivy.array([[1, 2], [3, 4]])) >>> x2 = ivy.Container(a=ivy.array([5, 6])) >>> y = ivy.Container.inner(x1, x2) >>> print(y) { a: ivy.array([17, 39]) }