vector

odl.vector(array, dtype=None, impl='numpy', device='cpu')

Create a vector from an array-like object.

Parameters

arrayarray-like

Array from which to create the vector. Scalars become one-dimensional vectors.

dtypeoptional

Set the data type of the vector manually with this option. By default, the space type is inferred from the input data.

implstr, optional

Impmlementation back-end for the space. See tensor_space_impl_names for available options.

Returns

vectorTensor

Vector created from the input array. Its concrete type depends on the provided arguments.

Notes

This is a convenience function and not intended for use in speed-critical algorithms.

Examples

Create one-dimensional vectors:

>>> odl.vector([1, 2, 3])  # No automatic cast to float
tensor_space(3, 'int64').element([1, 2, 3])
>>> odl.vector([1, 2, 3], dtype=float)
rn(3).element([ 1.,  2.,  3.])
>>> odl.vector([1, 2 - 1j, 3])
cn(3).element([ 1.+0.j,  2.-1.j,  3.+0.j])

Non-scalar types are also supported:

>>> odl.vector([True, True, False])
tensor_space(3, 'bool').element([ True,  True, False])

The function also supports multi-dimensional input:

>>> odl.vector([[1, 2, 3],
...             [4, 5, 6]])
tensor_space((2, 3), 'int64').element(
    [[1, 2, 3],
     [4, 5, 6]]
)