Linear algebra#

class ivy.data_classes.array.linear_algebra._ArrayWithLinearAlgebra[source]#

Bases: ABC

_abc_impl = <_abc._abc_data object>#
cholesky(*, upper=False, out=None)[source]#

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

Parameters:
  • self (Array) – input array having shape (…, M, M) and whose innermost two dimensions form square symmetric positive-definite matrices. Should have a floating-point data type.

  • upper (bool, default: False) – If True, the result must be the upper-triangular Cholesky factor U. If False, the result must be the lower-triangular Cholesky factor L. Default: False.

  • 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 – an array containing the Cholesky factors for each square matrix. If upper is False, the returned array must contain lower-triangular matrices; otherwise, the returned array must contain upper-triangular matrices. The returned array must have a floating-point data type determined by Type Promotion Rules and must have the same shape as self.

Examples

>>> x = ivy.array([[4.0, 1.0, 2.0, 0.5, 2.0],
...               [1.0, 0.5, 0.0, 0.0, 0.0],
...               [2.0, 0.0, 3.0, 0.0, 0.0],
...               [0.5, 0.0, 0.0, 0.625, 0.0],
...               [2.0, 0.0, 0.0, 0.0, 16.0]])
>>> y = x.cholesky(upper='false')
>>> print(y)
ivy.array([[ 2.  ,  0.5 ,  1.  ,  0.25,  1.  ],
...        [ 0.  ,  0.5 , -1.  , -0.25, -1.  ],
...        [ 0.  ,  0.  ,  1.  , -0.5 , -2.  ],
...        [ 0.  ,  0.  ,  0.  ,  0.5 , -3.  ],
...        [ 0.  ,  0.  ,  0.  ,  0.  ,  1.  ]])
cross(x2, /, *, axis=-1, out=None)[source]#

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

Parameters:
  • self (Array) – first input array. Should have a numeric data type.

  • x2 (Union[Array, NativeArray]) – second input array. Must be compatible with self (see broadcasting). Should have a numeric data type.

  • axis (int, default: -1) – the axis (dimension) of x1 and x2 containing the vectors for which to compute (default: -1) the cross product.vIf set to -1, the function computes the cross product for vectors defined by the last axis (dimension). Default: -1.

  • 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 – an array containing the element-wise products. The returned array must have a data type determined by type-promotion.

Examples

With ivy.Array instance inputs:

>>> x = ivy.array([1., 0., 0.])
>>> y = ivy.array([0., 1., 0.])
>>> z = x.cross(y)
>>> print(z)
ivy.array([0., 0., 1.])
det(*, out=None)[source]#
Return type:

Array

Examples

>>> x = ivy.array([[2.,4.],[6.,7.]])
>>> y = x.det()
>>> print(y)
ivy.array(-10.)
diag(*, k=0, out=None)[source]#

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

Return type:

Array

Examples

>>> x = ivy.array([[0, 1, 2],
>>>                [3, 4, 5],
>>>                [6, 7, 8]])
>>> x.diag(k=1)
ivy.array([1, 5])
diagonal(*, offset=0, axis1=-2, axis2=-1, out=None)[source]#

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

Parameters:
  • self (Array) – input array having shape (..., M, N) and whose innermost two dimensions form MxN matrices.

  • offset (int, default: 0) – offset specifying the off-diagonal relative to the main diagonal. - offset = 0: the main diagonal. - offset > 0: off-diagonal above the main diagonal. - offset < 0: off-diagonal below the main diagonal. Default: 0.

  • axis1 (int, default: -2) – axis to be used as the first axis of the 2-D sub-arrays from which the diagonals should be taken. Defaults to first axis (-2).

  • axis2 (int, default: -1) – axis to be used as the second axis of the 2-D sub-arrays from which the diagonals should be taken. Defaults to second axis (-1).

  • 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 – an array containing the diagonals and whose shape is determined by removing the last two dimensions and appending a dimension equal to the size of the resulting diagonals. The returned array must have the same data type as x.

Examples

With ivy.Array inputs:

>>> x = ivy.array([[1., 2.],
...                [3., 4.]])
>>> d = x.diagonal()
>>> print(d)
ivy.array([1., 4.])
>>> x = ivy.array([[[1., 2.],
...                 [3., 4.]],
...                [[5., 6.],
...                 [7., 8.]]])
>>> d = x.diagonal()
>>> print(d)
ivy.array([[1., 4.],
           [5., 8.]])
>>> x = ivy.array([[1., 2.],
...                [3., 4.]])
>>> d = x.diagonal(offset=1)
>>> print(d)
ivy.array([2.])
>>> x = ivy.array([[0, 1, 2],
...                [3, 4, 5],
...                [6, 7, 8]])
>>> d = x.diagonal(offset=-1, axis1=0)
>>> print(d)
ivy.array([3, 7])
eig(*, out=None)[source]#
Return type:

Tuple[Array]

eigh(*, UPLO='L', out=None)[source]#
Return type:

Tuple[Array]

eigvalsh(*, UPLO='L', out=None)[source]#

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

Parameters:
  • x – input array having shape (…, M, M) and whose innermost two dimensions form square matrices. Must have floating-point data type.

  • 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 – an array containing the computed eigenvalues. The returned array must have shape (…, M) and have the same data type as x.

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

With ivy.Array inputs:

>>> x = ivy.array([[[1.0,2.0],[2.0,1.0]]])
>>> y = ivy.eigvalsh(x)
>>> print(y)
ivy.array([[-1.,  3.]])
inner(x2, /, *, out=None)[source]#

Return the inner product of two vectors self and x2.

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

inv(*, adjoint=False, out=None)[source]#

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

Parameters:
  • self (Array) – input array having shape (..., M, M) and whose innermost two dimensions form square matrices. Should have a floating-point data type.

  • 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 – an array containing the multiplicative inverses. The returned array must have a floating-point data type determined by type-promotion and must have the same shape as x.

Examples

With ivy.Array inputs:

>>> x = ivy.array([[1.0, 2.0],[3.0, 4.0]])
>>> y = x.inv()
>>> print(y)
ivy.array([[-2., 1.],[1.5, -0.5]])
matmul(x2, /, *, transpose_a=False, transpose_b=False, adjoint_a=False, adjoint_b=False, out=None)[source]#

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

Parameters:
  • self (Array) – first input array. Should have a numeric data type. Must have at least one dimension.

  • x2 (Union[Array, NativeArray]) – second input array. Should have a numeric data type. Must have at least one dimension.

  • transpose_a (bool, default: False) – if True, x1 is transposed before multiplication.

  • transpose_b (bool, default: False) – if True, x2 is transposed before multiplication.

  • adjoint_a (bool, default: False) – If True, takes the conjugate of the matrix then the transpose of the matrix. adjoint_a and transpose_a can not be true at the same time.

  • adjoint_b (bool, default: False) – If True, takes the conjugate of the matrix then the transpose of the matrix. adjoint_b and transpose_b can not be true at the same time.

  • 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 – An array containing the output of matrix multiplication. The returned array must have a data type determined by type-promotion. More details can be found in ivy.matmul.

Examples

With ivy.Array instance inputs:

>>> x = ivy.array([1., 4.])
>>> y = ivy.array([3., 2.])
>>> z = x.matmul(y)
>>> print(z)
ivy.array(11.)
matrix_norm(*, ord='fro', axis=(-2, -1), keepdims=False, dtype=None, out=None)[source]#

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

Parameters:
  • self (Array) – Input array having shape (…, M, N) and whose innermost two dimensions form MxN matrices. Should have a floating-point data type.

  • ord (Union[int, float, Literal[inf, -inf, 'fro', 'nuc']], default: 'fro') – Order of the norm. Default is “fro”.

  • axis (Tuple[int, int], default: (-2, -1)) – specifies the axes that hold 2-D matrices. Default: (-2, -1).

  • keepdims (bool, default: False) – If this is set to True, the axes which are normed over are left in the result as dimensions with size one. With this option the result will broadcast correctly against the original x. Default is False.

  • dtype (Optional[Union[Dtype, NativeDtype]], default: None) – If specified, the input tensor is cast to dtype before performingthe operation, and the returned tensor’s type will be dtype. Default: None

  • 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 – Matrix norm of the array at specified axes.

Examples

>>> x = ivy.array([[1.1, 2.2, 3.3], [1.0, 2.0, 3.0]])
>>> y = x.matrix_norm(ord=1)
>>> print(y)
ivy.array(6.3)
>>> x = ivy.arange(8, dtype=float).reshape((2, 2, 2))
>>> y = x.matrix_norm(ord="nuc", keepdims=True)
>>> print(y)
ivy.array([[[ 4.24]],
        [[11.4 ]]])
matrix_power(n, /, *, out=None)[source]#
Return type:

Array

matrix_rank(*, atol=None, rtol=None, hermitian=False, out=None)[source]#

ivy.Array instance method variant of ivy.matrix_rank. This method returns the rank (i.e., number of non-zero singular values) of a matrix (or a stack of matrices).

Parameters:
  • self (Array) – input array having shape (..., M, N) and whose innermost two dimensions form MxN matrices. Should have a floating-point data type.

  • atol (Optional[Union[float, Tuple[float]]], default: None) – absolute tolerance. When None it’s considered to be zero.

  • rtol (Optional[Union[float, Tuple[float]]], default: None) – relative tolerance for small singular values. Singular values approximately less than or equal to rtol * largest_singular_value are set to zero. If a float, the value is equivalent to a zero-dimensional array having a floating-point data type determined by type-promotion (as applied to x) and must be broadcast against each matrix. If an array, must have a floating-point data type and must be compatible with shape(x)[:-2] (see broadcasting). If None, the default value is max(M, N) * eps, where eps must be the machine epsilon associated with the floating-point data type determined by type-promotion (as applied to x). Default: None.

  • hermitian (Optional[bool], default: False) – indicates whether x is Hermitian. When hermitian=True, x is assumed to be Hermitian, enabling a more efficient method for finding eigenvalues, but x is not checked inside the function. Instead, We just use the lower triangular of the matrix to compute. Default: False.

  • 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 container containing the ranks. The returned array must have a floating-point data type determined by type-promotion and must have shape (...) (i.e., must have a shape equal to shape(x)[:-2]).

Examples

1. Full Matrix >>> x = ivy.array([[1., 2.], [3., 4.]]) >>> ivy.matrix_rank(x) ivy.array(2.)

2. Rank Deficient Matrix >>> x = ivy.array([[1., 0.], [0., 0.]]) >>> ivy.matrix_rank(x) ivy.array(1.)

3. 1 Dimension - rank 1 unless all 0 >>> x = ivy.array([[1., 1.]) >>> ivy.matrix_rank(x) ivy.array(1.)

>>> x = ivy.array([[0., 0.])
>>> ivy.matrix_rank(x)
ivy.array(0)
matrix_transpose(*, conjugate=False, out=None)[source]#

Transpose a matrix (or a stack of matrices) x.

Parameters:
  • self (Array) – input array having shape (..., M, N) and whose innermost two dimensions form MxN matrices.

  • 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 – an array containing the transpose for each matrix and having shape (..., N, M). The returned array must have the same data type as x.

Examples

With ivy.Array instance inputs:

>>> x = ivy.array([[1., 2.], [0., 3.]])
>>> y = x.matrix_transpose()
>>> print(y)
ivy.array([[1., 0.],
           [2., 3.]])
outer(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]])
pinv(*, rtol=None, out=None)[source]#

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

Parameters:
  • self (Array) – input array having shape (..., M, N) and whose innermost two dimensions form MxN matrices. Should have a floating-point data type.

  • rtol (Optional[Union[float, Tuple[float]]], default: None) – relative tolerance for small singular values. More details in ivy.pinv.

  • 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 – An array containing the pseudo-inverses. More details in ivy.pinv.

Examples

>>> x = ivy.array([[1., 2.], [3., 4.]])
>>> y = x.pinv()
>>> print(y)
ivy.array([[-1.99999988,  1.        ],
       [ 1.5       , -0.5       ]])
>>> x = ivy.array([[1., 2.], [3., 4.]])
>>> z = ivy.zeros((2,2))
>>> x.pinv(rtol=0, out=z)
>>> print(z)
ivy.array([[-1.99999988,  1.        ],
       [ 1.5       , -0.5       ]])
qr(*, mode='reduced', out=None)[source]#

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

Returns the qr decomposition x = QR of a full column rank matrix (or a stack of matrices), where Q is an orthonormal matrix (or a stack of matrices) and R is an upper-triangular matrix (or a stack of matrices).

Parameters:
  • self (Array) – input array having shape (…, M, N) and whose innermost two dimensions form MxN matrices of rank N. Should have a floating-point data type.

  • mode (str, default: 'reduced') – decomposition mode. Should be one of the following modes: - ‘reduced’: compute only the leading K columns of q, such that q and r have dimensions (…, M, K) and (…, K, N), respectively, and where K = min(M, N). - ‘complete’: compute q and r with dimensions (…, M, M) and (…, M, N), respectively. Default: ‘reduced’.

  • out (Optional[Tuple[Array, Array]], default: None) – optional output tuple of arrays, for writing the result to. The arrays must have shapes that the inputs broadcast to.

Return type:

Tuple[Array, Array]

Returns:

ret – a namedtuple (Q, R) whose - first element must have the field name Q and must be an array whose shape depends on the value of mode and contain matrices with orthonormal columns. If mode is ‘complete’, the array must have shape (…, M, M). If mode is ‘reduced’, the array must have shape (…, M, K), where K = min(M, N). The first x.ndim-2 dimensions must have the same size as those of the input array x. - second element must have the field name R and must be an array whose shape depends on the value of mode and contain upper-triangular matrices. If mode is ‘complete’, the array must have shape (…, M, N). If mode is ‘reduced’, the array must have shape (…, K, N), where K = min(M, N). The first x.ndim-2 dimensions must have the same size as those of the input x.

Examples

>>> x = ivy.array([[1.,2.,3.],[4.,5.,6.],[7.,8.,9.]])
>>> q, r = x.qr(mode='reduced')
>>> print(q)
ivy.array([[-0.12309149,  0.90453403,  0.40824829],
    [-0.49236596,  0.30151134, -0.81649658],
    [-0.86164044, -0.30151134,  0.40824829]])
>>> print(r)
ivy.array([[-8.12403841e+00,-9.60113630e+00, -1.10782342e+01],
    [ 0.00000000e+00,  9.04534034e-01,  1.80906807e+00],
    [ 0.00000000e+00,  0.00000000e+00, -8.88178420e-16]])
slogdet()[source]#

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

Parameters:

self (Array) – input array having shape (…, M, M) and whose innermost two dimensions form square matrices. Should have a floating-point data type.

Return type:

Tuple[Array, Array]

Returns:

ret

This function returns NamedTuple with two values -

sign: An array containing a number representing the sign of the determinant for each square matrix.

logabsdet: An array containing natural log of the absolute determinant of each square matrix.

Examples

>>> x = ivy.array([[1.0, 2.0],
...                [3.0, 4.0]])
>>> y = x.slogdet()
>>> print(y)
slogdet(sign=ivy.array(-1.), logabsdet=ivy.array(0.69314718))
>>> x = ivy.array([[1.2, 2.0, 3.1],
...                [6.0, 5.2, 4.0],
...                [9.0, 8.0, 7.0]])
>>> y = x.slogdet()
>>> print(y)
slogdet(sign=ivy.array(-1.), logabsdet=ivy.array(1.098611))
solve(x2, /, *, adjoint=False, out=None)[source]#
Return type:

Array

svd(*, compute_uv=True, full_matrices=True)[source]#

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

Parameters:
  • self (Array) – input array having shape (..., M, N) and whose innermost two dimensions form matrices on which to perform singular value decomposition. Should have a floating-point data type.

  • full_matrices (bool, default: True) – If True, compute full-sized U and Vh, such that U has shape (..., M, M) and Vh has shape (..., N, N). If False, compute on the leading K singular vectors, such that U has shape (..., M, K) and Vh has shape (..., K, N) and where K = min(M, N). Default: True.

  • compute_uv (bool, default: True) – If True then left and right singular vectors will be computed and returned in U and Vh, respectively. Otherwise, only the singular values will be computed, which can be significantly faster.

  • note:: (..) – with backend set as torch, svd with still compute left and right singular vectors irrespective of the value of compute_uv, however Ivy will still only return the singular values.

Return type:

Union[Array, Tuple[Array, ...]]

Returns:

  • .. note:: – once complex numbers are supported, each square matrix must be Hermitian.

  • ret – a namedtuple (U, S, Vh). More details in ivy.svd.

    Each returned array must have the same floating-point data type as x.

Examples

With ivy.Array input:

>>> x = ivy.random_normal(shape = (9, 6))
>>> U, S, Vh = x.svd()
>>> print(U.shape, S.shape, Vh.shape)
(9, 9) (6,) (6, 6)

With reconstruction from SVD, result is numerically close to x

>>> reconstructed_x = ivy.matmul(U[:,:6] * S, Vh)
>>> print((reconstructed_x - x > 1e-3).sum())
ivy.array(0)
>>> U, S, Vh = x.svd(full_matrices = False)
>>> print(U.shape, S.shape, Vh.shape)
(9, 6) (6,) (6, 6)
svdvals(*, out=None)[source]#
Return type:

Array

tensordot(x2, /, *, axes=2, out=None)[source]#
Return type:

Array

tensorsolve(x2, /, *, axes=None)[source]#
Return type:

Tuple[Array]

trace(*, offset=0, axis1=0, axis2=1, out=None)[source]#

ivy.Array instance method variant of ivy.trace. This method Returns the sum along the specified diagonals of a matrix (or a stack of matrices).

Parameters:
  • self (Array) – input array having shape (..., M, N) and whose innermost two dimensions form MxN matrices. Should have a floating-point data type.

  • offset (int, default: 0) – Offset of the diagonal from the main diagonal. Can be both positive and negative. Defaults to 0.

  • axis1 (int, default: 0) – axis to be used as the first axis of the 2-D sub-arrays from which the diagonals should be taken. Defaults to 0. .

  • axis2 (int, default: 1) – axis to be used as the second axis of the 2-D sub-arrays from which the diagonals should be taken. Defaults to 1. .

  • 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 – an array containing the traces and whose shape is determined by removing the last two dimensions and storing the traces in the last array dimension. For example, if x has rank k and shape (I, J, K, ..., L, M, N), then an output array has rank k-2 and shape (I, J, K, ..., L) where

out[i, j, k, …, l] = trace(a[i, j, k, …, l, :, :])

The returned array must have the same data type as x.

Examples

>>> x = ivy.array([[1., 2.], [3., 4.]])
>>> y = x.trace()
>>> print(y)
ivy.array(5.)
>>> x = ivy.array([[1., 2., 4.], [6., 5., 3.]])
>>> y = ivy.Array.trace(x)
>>> print(y)
ivy.array(6.)
vander(*, N=None, increasing=False, out=None)[source]#

ivy.Array instance method variant of ivy.vander. This method Returns the Vandermonde matrix of the input array.

Parameters:
  • self (Array) – 1-D input array.

  • N (Optional[int], default: None) – Number of columns in the output. If N is not specified, a square array is returned (N = len(x))

  • increasing (bool, default: False) – Order of the powers of the columns. If True, the powers increase from left to right, if False (the default) they are reversed.

  • out (Optional[Array], default: None) – optional output array, for writing the result to.

Return type:

Array

Returns:

ret – an array containing the Vandermonde matrix.

Examples

>>> x = ivy.array([1, 2, 3, 5])
>>> ivy.vander(x)
ivy.array(
[[  1,   1,   1,   1],
    [  8,   4,   2,   1],
    [ 27,   9,   3,   1],
    [125,  25,   5,   1]]
    )
>>> x = ivy.array([1, 2, 3, 5])
>>> ivy.vander(x, N=3)
ivy.array(
[[ 1,  1,  1],
    [ 4,  2,  1],
    [ 9,  3,  1],
    [25,  5,  1]]
    )
>>> x = ivy.array([1, 2, 3, 5])
>>> ivy.vander(x, N=3, increasing=True)
ivy.array(
[[ 1,  1,  1],
    [ 1,  2,  4],
    [ 1,  3,  9],
    [ 1,  5, 25]]
    )
vecdot(x2, /, *, axis=-1, out=None)[source]#
Return type:

Array

vector_norm(*, axis=None, keepdims=False, ord=2, dtype=None, out=None)[source]#

ivy.Array instance method variant of ivy.vector_norm. This method computes the vector norm of a vector (or batch of vectors).

Parameters:
  • self (Array) – Input array. Should have a floating-point data type.

  • axis (Optional[Union[int, Sequence[int]]], default: None) – If an integer, axis specifies the axis (dimension) along which to compute vector norms. If an n-tuple, axis specifies the axes (dimensions) along which to compute batched vector norms. If None, the vector norm must be computed over all array values (i.e., equivalent to computing the vector norm of a flattened array). Negative indices are also supported. Default: None.

  • keepdims (bool, default: False) – If True, the axes (dimensions) specified by axis must be included in the result as singleton dimensions, and, accordingly, the result must be compatible with the input array (see broadcasting). Otherwise, if False, the axes (dimensions) specified by axis must not be included in the result. Default: False.

  • ord (Union[int, float, Literal[inf, -inf]], default: 2) –

    order of the norm. The following mathematical norms are supported:

    ord

    description

    1

    L1-norm (Manhattan)

    2

    L2-norm (Euclidean)

    inf

    infinity norm

    (int,float >= 1)

    p-norm

    The following non-mathematical “norms” are also supported:

    ord

    description

    0

    sum(a != 0)

    -inf

    min(abs(a))

    (int,float < 1)

    sum(abs(a)**ord)**(1./ord)

    Default: 2.

  • dtype (Optional[Union[Dtype, NativeDtype]], default: None) – data type that may be used to perform the computation more precisely. The input array self gets cast to dtype before the function’s computations.

  • 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 – an array containing the vector norms. If axis is None, the returned array must be a zero-dimensional array containing a vector norm. If axis is a scalar value (int or float), the returned array must have a rank which is one less than the rank of self. If axis is a n-tuple, the returned array must have a rank which is n less than the rank of self. The returned array must have a floating-point data type determined by type-promotion.

Examples

>>> x = ivy.array([1., 2., 3.])
>>> y = x.vector_norm()
>>> print(y)
ivy.array([3.7416575])
vector_to_skew_symmetric_matrix(*, out=None)[source]#
Return type:

Array