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.
Remove terms with coefficients of absolute value atol or less.
D.get(k[,d]) -> D[k] if k in D, else d.
If key is not found, d is returned if given, otherwise KeyError is raised.
as a 2-tuple; but raise KeyError if D is empty.
update()D.update([E, ]**F) -> None. Update D from mapping/iterable E and F.