ProductSpaceElement.ufuncs

property ProductSpaceElement.ufuncs

ProductSpaceUfuncs, access to Numpy style ufuncs.

These are always available if the underlying spaces are TensorSpace.

See also

odl.util.ufuncs.TensorSpaceUfuncs

Base class for ufuncs in TensorSpace spaces, subspaces may override this for greater efficiency.

odl.util.ufuncs.ProductSpaceUfuncs

For a list of available ufuncs.

Examples

>>> r22 = odl.ProductSpace(odl.rn(2), 2)
>>> x = r22.element([[1, -2], [-3, 4]])
>>> x.ufuncs.absolute()
ProductSpace(rn(2), 2).element([
    [ 1.,  2.],
    [ 3.,  4.]
])

These functions can also be used with non-vector arguments and support broadcasting, per component and even recursively:

>>> x.ufuncs.add([1, 2])
ProductSpace(rn(2), 2).element([
    [ 2.,  0.],
    [-2.,  6.]
])
>>> x.ufuncs.subtract(1)
ProductSpace(rn(2), 2).element([
    [ 0., -3.],
    [-4.,  3.]
])

There is also support for various reductions (sum, prod, min, max):

>>> x.ufuncs.sum()
0.0

Writing to out is also supported:

>>> y = r22.element()
>>> result = x.ufuncs.absolute(out=y)
>>> result
ProductSpace(rn(2), 2).element([
    [ 1.,  2.],
    [ 3.,  4.]
])
>>> result is y
True