The operators specified in this module act like their matrix equivalent, and attempt to match tbe basic building blocks in NumPy and other numerical packages.
Create a LinearOperator that emulates a diagonal matrix.
Creates a LinearOperator that scales each row of its input by the corresponding element of the input vector v. The length of the vector v defines the shape of the operator (n by n).
| Parameters: | v : 1-D array
|
|---|---|
| Returns: | LinearOperator
|
See also
Examples
>>> from pyop.operators import diag
>>> from pyop import toMatrix
>>> import numpy as np
>>> toMatrix(diag(np.array([1, 2, 3, 4])))
array([[ 1., 0., 0., 0.],
[ 0., 2., 0., 0.],
[ 0., 0., 3., 0.],
[ 0., 0., 0., 4.]])
PyOp version of eye array function (only 2D).
Returns a new LinearOperator that emulates the identity matrix.
| Parameters: | shape : pair
|
|---|---|
| Returns: | LinearOperator
|
See also
Examples
>>> from pyop.operators import eye
>>> from pyop import toMatrix
>>> toMatrix(eye((2, 1)))
array([[ 1.],
[ 0.]])
>>> s = (2,2)
>>> toMatrix(eye(s))
array([[ 1., 0.],
[ 0., 1.]])
PyOp version of ones array function (only 2D).
Returns a new LinearOperator that emulates a matrix filled with ones.
| Parameters: | shape : pair
|
|---|---|
| Returns: | LinearOperator
|
See also
Examples
>>> from pyop.operators import ones
>>> from pyop import toMatrix
>>> toMatrix(ones((2, 1)))
array([[ 1.],
[ 1.]])
>>> s = (2,2)
>>> toMatrix(ones(s))
array([[ 1., 1.],
[ 1., 1.]])
Select only certain rows of a matrix.
This operator selects only certain rows from a matrix. It can be particularly useful for consesus or sharing optimization problems.
The input perm can be in any order, and duplicates can be made. In this manner, it is possible to make a permutation matrix by including an input that includes each row once and only once.
| Parameters: | rows : integer
perm : list
|
|---|---|
| Returns: | LinearOperator
|
See also
Examples
>>> from pyop.operators import select
>>> import numpy as np
>>> S = select(4, [0, 1, 3])
>>> S(np.array([1, 2, 3, 4]))
array([1, 2, 4])
>>> S = select(4, [0, 1, 1])
>>> S(np.array([1, 2, 3, 4]))
array([1, 2, 2])
PyOp version of zeros array function (only 2D).
Returns a new LinearOperator that emulates a matrix filled with zeros.
| Parameters: | shape : pair
|
|---|---|
| Returns: | LinearOperator
|
See also
Examples
>>> from pyop.operators import zeros
>>> from pyop import toMatrix
>>> toMatrix(zeros((2, 1)))
array([[ 0.],
[ 0.]])
>>> s = (2,2)
>>> toMatrix(zeros(s))
array([[ 0., 0.],
[ 0., 0.]])