aslinearoperator#
- scipy.sparse.linalg.aslinearoperator(A)[source]#
Return A as a
LinearOperator.See the
LinearOperatordocumentation for additional information.- Parameters:
- Aobject
Object to convert to a
LinearOperator. May be any one of the following types:scipy.sparsearray (e.g.csr_array,lil_array, etc.)An object with
.shapeand.matvecattributes
- Returns:
- BLinearOperator
A
LinearOperatorcorresponding with A
Notes
If A has no
.dtypeattribute, the data type is determined by callingLinearOperator.matvec- set the.dtypeattribute to prevent this call upon the linear operator creation.Array API Standard Support
aslinearoperatorhas support for Python Array API Standard compatible backends in addition to NumPy. The following combinations of backend and device (or other capability) are supported.Library
CPU
GPU
NumPy
✅
n/a
CuPy
n/a
✅
PyTorch
✅
✅
JAX
✅
✅
Dask
✅
n/a
See Support for the array API standard for more information.
Examples
>>> import numpy as np >>> from scipy.sparse.linalg import aslinearoperator >>> M = np.array([[1,2,3],[4,5,6]], dtype=np.int32) >>> aslinearoperator(M) <2x3 MatrixLinearOperator with dtype=int32>