matrix_props.kp_norm

Kp-norm for matrices.

Module Contents

Functions

kp_norm(mat, k, p)

Compute the kp_norm of vector or matrix.

matrix_props.kp_norm.kp_norm(mat, k, p)

Compute the kp_norm of vector or matrix.

Calculate the p-norm of a vector or the k-largest singular values of a matrix.

Examples

To compute the p-norm of a vector:

>>> import numpy as np
>>> from toqito.matrix_props import kp_norm
>>> from toqito.states import bell
>>> '%.2f' % kp_norm(bell(0), 1, np.inf)
'1.00'

To compute the k-largest singular values of a matrix:

>>> import numpy as np
>>> from toqito.matrix_props import kp_norm
>>> from toqito.rand import random_unitary
>>> '%.2f' % kp_norm(random_unitary(5), 5, 2)
'2.24'

Note

You do not need to use ‘%.2f’ % when you use this function. We use this to format our output such that doctest compares the calculated output to the expected output upto two decimal points only. The accuracy of the solvers can calculate the float output to a certain amount of precision such that the value deviates after a few digits of accuracy.

Parameters:
  • mat (numpy.ndarray) – 2D numpy ndarray

  • k (int) – The number of singular values to take.

  • p (int) – The order of the norm.

Returns:

The kp-norm of a matrix.

Return type:

float