Parameters
----------
- left, right : matrix
- The two matrices to append to one another.
+ left : matrix
+ The "original" matrix, the one that will wind up on the left.
+
+ right : matrix
+ The matrix to be appended on the right of ``left``.
Returns
-------
Parameters
----------
- top, bottom : matrix
- The two matrices to append to one another.
+ top : matrix
+ The "original" matrix, the one that will wind up on top.
+
+ bottom : matrix
+ The matrix to be appended below ``top``.
Returns
-------
Parameters
----------
- vec1, vec2 : matrix
- The two vectors whose inner product you want.
+ vec1 : matrix
+ The first vector, whose inner product with ``vec2`` you want.
+
+ vec2 : matrix
+ The second vector, whose inner product with ``vec1`` you want.
Returns
-------
return sqrt(inner_product(matrix_or_vector, matrix_or_vector))
+def specnorm(mat):
+ """
+ Return the spectral norm of a matrix.
+
+ The spectral norm of a matrix is its largest singular value, and it
+ corresponds to the operator norm induced by the vector Euclidean norm.
+
+ Parameters
+ ----------
+
+ mat : matrix
+ The matrix whose spectral norm you want.
+
+ Examples:
+
+ >>> specnorm(identity(3))
+ 1.0
+
+ >>> specnorm(5*identity(4))
+ 5.0
+
+ """
+ num_eigs = min(mat.size)
+ eigs = matrix(0, (num_eigs, 1), tc='d')
+ typecode = 'd'
+ if any([isinstance(entry, complex) for entry in mat]):
+ typecode = 'z'
+ dummy = matrix(mat, mat.size, tc=typecode)
+ gesdd(dummy, eigs)
+
+ if len(eigs) > 0:
+ return eigs[0]
+ else:
+ return 0
+
+
def vec(mat):
"""
Create a long vector in column-major order from ``mat``.