outer#

ivy.outer(x1, x2, /, *, out=None)[source]#

Return the outer product of two vectors x1 and x2.

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:

Array

Returns:

ret – a two-dimensional array containing the outer product and whose shape is (N, M). The returned array must have a data type determined by Type Promotion Rules.

This function conforms to the Array API Standard. This docstring is an extension of the docstring in the standard.

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

>>> x = ivy.array([[1., 2.],[3., 4.]])
>>> y = ivy.array([[5., 6.],[7., 8.]])
>>> d = ivy.outer(x,y)
>>> print(d)
ivy.array([[ 5.,  6.,  7.,  8.],
            [10., 12., 14., 16.],
            [15., 18., 21., 24.],
            [20., 24., 28., 32.]])
>>> d = ivy.outer(x, 1)
>>> print(d)
ivy.array([[1.],
            [2.],
            [3.],
            [4.]])
>>> x = ivy.array([[[1., 2.],[3., 4.]],[[5., 6.],[7., 8.]]])
>>> y = ivy.array([[[9., 10.],[11., 12.]],[[13., 14.],[15., 16.]]])
>>> d = ivy.outer(x, y)
>>> print(d)
ivy.array([[  9.,  10.,  11.,  12.,  13.,  14.,  15.,  16.],
            [ 18.,  20.,  22.,  24.,  26.,  28.,  30.,  32.],
            [ 27.,  30.,  33.,  36.,  39.,  42.,  45.,  48.],
            [ 36.,  40.,  44.,  48.,  52.,  56.,  60.,  64.],
            [ 45.,  50.,  55.,  60.,  65.,  70.,  75.,  80.],
            [ 54.,  60.,  66.,  72.,  78.,  84.,  90.,  96.],
            [ 63.,  70.,  77.,  84.,  91.,  98., 105., 112.],
            [ 72.,  80.,  88.,  96., 104., 112., 120., 128.]])
Array.outer(self, x2, /, *, out=None)[source]#

Compute the outer product between two arrays.

Parameters:
  • self (ivy.Array) – The first input array.

  • x2 (ivy.Array or ivy.NativeArray) – The second input array.

  • out (ivy.Array, optional) – Output array. If provided, it must have the same shape as the expected output.

Return type:

Array

Returns:

ivy.Array – The outer product of the two arrays.

Examples

>>> x = ivy.array([1, 2, 3])
>>> y = ivy.array([4, 5])
>>> z = x.outer(y)
>>> print(z)
ivy.array([[ 4,  5],
           [ 8, 10],
           [12, 15]])
Container.outer(self, x2, /, *, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, out=None)[source]#

Return the outer product of two arrays or containers.

The instance method implementation of the static method static_outer of the ivy.Container class. It calculates the outer product of two input arrays or containers along the last dimension and returns the resulting container. The input arrays should be either ivy.Container, ivy.Array, or ivy.NativeArray. The output container shape is the concatenation of the shapes of the input containers along the last dimension.

Parameters:
  • self (ivy.Container) – Input container of shape (…,B) where the last dimension represents B elements.

  • x2 (Union[ivy.Container, ivy.Array, ivy.NativeArray]) – Second input array or container of shape (…, N) where the last dimension represents N elements.

  • key_chains (Optional[Union[List[str], Dict[str, str]]]) – The key-chains to apply or not apply the method to. Default is None.

  • to_apply (bool) – If True, the method will be applied to key_chains, otherwise key_chains will be skipped.Default is True.

  • prune_unapplied (bool) – Whether to prune key_chains for which the function was not applied. Default is False.

  • map_sequences (bool) – Whether to also map the method to sequences (lists, tuples). Default is False.

  • out (Optional[ivy.Container]) – Optional output container to write the result to. If not provided, a new container will be created.

Return type:

Container

Returns:

ivy.Container – A new container of shape (…, M, N) representing the outer product of the input arrays or containers along the last dimension.

Examples

>>> x = ivy.array([[1., 2.],[3., 4.]])
>>> y = ivy.array([[5., 6.],[7., 8.]])
>>> d = ivy.outer(x,y)
>>> print(d)
ivy.array([[ 5.,  6.,  7.,  8.],
            [10., 12., 14., 16.],
            [15., 18., 21., 24.],
            [20., 24., 28., 32.]])