summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--polymatrix/polymatrix/mixins.py11
1 files changed, 11 insertions, 0 deletions
diff --git a/polymatrix/polymatrix/mixins.py b/polymatrix/polymatrix/mixins.py
index 4cb89b3..f5cdb48 100644
--- a/polymatrix/polymatrix/mixins.py
+++ b/polymatrix/polymatrix/mixins.py
@@ -34,6 +34,17 @@ class PolyMatrixMixin(ABC):
p.at(*entry) # if you have a MatrixIndex
"""
+ def scalar(self) -> PolyDict:
+ """
+ If the polymatrix is scalar, that is, a 1x1 matrix, this is a shorthand
+ for .at(0,0) for readability. Raises an error polymatrix is not scalar.
+ """
+ if self.shape != (1,1):
+ raise AttributeError("Use of .scalar() is not allowed because "
+ f"it has shape {self.shape}")
+
+ return self.at(0, 0)
+
def entries(self) -> Iterable[tuple[MatrixIndex, PolyDict]]:
"""
Iterate over the non-zero entries of the polynomial matrix.