LinearDict(terms: Optional[Mapping[TVector, Union[complex, float]]] = None, validator: Callable[TVector, bool] = <function LinearDict.<lambda>>)¶
Represents linear combination of things.LinearDict implements the basic linear algebraic operations of vectoraddition and scalar multiplication for linear combinations of abstractvectors. Keys represent the vectors, values represent their coefficients.The only requirement on the keys is that they be hashable (i.e. areimmutable and implement hash and eq with equal objects hashingto equal values).A consequence of treating keys as opaque is that all relationships betweenthe keys other than equality are ignored. In particular, keys are allowedto be linearly dependent.
__init__(terms: Optional[Mapping[TVector, Union[complex, float]]] = None, validator: Callable[TVector, bool] = <function LinearDict.<lambda>>) → None¶
Initializes linear combination from a collection of terms.
terms – Mapping of abstract vectors to coefficients in the linear combination being initialized.
validator – Optional predicate that determines whether a vector is valid or not. Dictionary and linear algebra operations that would lead to the inclusion of an invalid vector into the combination raise ValueError exception. By default all vectors are valid.