Matrix Operators

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.

diag(v)[source]

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

An array by which to scale each of rows of the input.

Returns:

LinearOperator

A LinearOperator that scales np.array inputs.

See also

zeros
Matrix free version of the zeros matrix.
ones
Matrix free version of the ones matrix.
eye
Matrix free version of the eye matrix.
select
Select certain rows out of a matrix.

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.]])
eye(shape)[source]

PyOp version of eye array function (only 2D).

Returns a new LinearOperator that emulates the identity matrix.

Parameters:

shape : pair

The shape of the LinearOperator (if it were a matrix).

Returns:

LinearOperator

A functional version of numpy.eye()

See also

zeros
Matrix free version of the zeros matrix.
ones
Matrix free version of the ones matrix.
diag
Convert a 1D array to matrix free diagonal matrix.
select
Select certain rows out of a matrix.

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.]])
ones(shape)[source]

PyOp version of ones array function (only 2D).

Returns a new LinearOperator that emulates a matrix filled with ones.

Parameters:

shape : pair

The shape of the LinearOperator (if it were a matrix).

Returns:

LinearOperator

A functional version of numpy.ones()

See also

zeros
Matrix free version of the zeros matrix.
eye
Matrix free version of the eye matrix.
diag
Convert a 1D array to matrix free diagonal matrix.
select
Select certain rows out of a matrix.

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(rows, perm)[source]

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

The number of total rows to be selected from.

perm : list

A list of the rows to take. This will define the shape of the resulting LinearOperator.

Returns:

LinearOperator

A LinearOperator that performs the selection on np.array inputs.

See also

zeros
Matrix free version of the zeros matrix.
ones
Matrix free version of the ones matrix.
eye
Matrix free version of the eye matrix.
diag
Convert a 1D array to matrix free diagonal matrix.

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])
zeros(shape)[source]

PyOp version of zeros array function (only 2D).

Returns a new LinearOperator that emulates a matrix filled with zeros.

Parameters:

shape : pair

The shape of the LinearOperator (if it were a matrix).

Returns:

LinearOperator

A functional version of numpy.zeros()

See also

ones
Matrix free version of the ones matrix.
eye
Matrix free version of the eye matrix.
diag
Convert a 1D array to matrix free diagonal matrix.
select
Select certain rows out of a matrix.

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.]])

Matrix Free Linear Operators

Navigation