{ } Raw JSON

bundles / scipy 1.17.1 / scipy / linalg / _matfuncs / funm

function

scipy.linalg._matfuncs:funm

source: /scipy/linalg/_matfuncs.py :807

Signature

def   funm ( A func disp = True )

Summary

Evaluate a matrix function specified by a callable.

Extended Summary

Returns the value of matrix-valued function f at A. The function f is an extension of the scalar-valued function func to matrices.

The documentation is written assuming array arguments are of specified "core" shapes. However, array argument(s) of this function may have additional "batch" dimensions prepended to the core shape. In this case, the array is treated as a batch of lower-dimensional slices; see linalg_batch for details. Note that calls with zero-size batches are unsupported and will raise a ValueError.

Parameters

A : (N, N) array_like

Matrix at which to evaluate the function

func : callable

Callable object that evaluates a scalar function f. Must be vectorized (eg. using vectorize).

disp : bool, optional

Print warning if error in the result is estimated large instead of returning estimated error. (Default: True)

Returns

funm : (N, N) ndarray

Value of the matrix function specified by func evaluated at A

errest : float

(if disp == False)

1-norm of the estimated error, ||err||_1 / ||A||_1

Notes

This function implements the general algorithm based on Schur decomposition (Algorithm 9.1.1. in [1]).

If the input matrix is known to be diagonalizable, then relying on the eigendecomposition is likely to be faster. For example, if your matrix is Hermitian, you can do

>>> from scipy.linalg import eigh
>>> def funm_herm(a, func, check_finite=False):
...     w, v = eigh(a, check_finite=check_finite)
...     ## if you further know that your matrix is positive semidefinite,
...     ## you can optionally guard against precision errors by doing
...     # w = np.maximum(w, 0)
...     w = func(w)
...     return (v * w).dot(v.conj().T)

Examples

import numpy as np
from scipy.linalg import funm
a = np.array([[1.0, 3.0], [1.0, 4.0]])
funm(a, lambda x: x*x)
a.dot(a)

Aliases

  • scipy.linalg.funm

Referenced by

This package