Vectorizable

class menpo.base.Vectorizable[source]

Bases: object

Flattening of rich objects to vectors and rebuilding them back.

Interface that provides methods for ‘flattening’ an object into a vector, and restoring from the same vectorized form. Useful for statistical analysis of objects, which commonly requires the data to be provided as a single vector.

as_vector(**kwargs)[source]

Returns a flattened representation of the object as a single vector.

Returns:

vector : (N,) ndarray

The core representation of the object, flattened into a single vector. Note that this is always a view back on to the original object, but is not writable.

from_vector(vector)[source]

Build a new instance of the object from it’s vectorized state.

self is used to fill out the missing state required to rebuild a full object from it’s standardized flattened state. This is the default implementation, which is which is a deepcopy of the object followed by a call to from_vector_inplace(). This method can be overridden for a performance benefit if desired.

Parameters:

vector : (n_parameters,) ndarray

Flattened representation of the object.

Returns:

object : type(self)

An new instance of this class.

from_vector_inplace(vector)[source]

Update the state of this object from a vector form.

Parameters:

vector : (n_parameters,) ndarray

Flattened representation of this object

n_parameters[source]

The length of the vector that this object produces.

Type:int