matrix.Matrix.add_criteria

Matrix.add_criteria(*criteria, weights: tuple[float], **choices_to_ratings)

Add multiple criteria into the matrix to evaluate each choice against.

Parameters

*criteria (str) – Names of the criteria to add.

Keyword Arguments
  • weights (tuple[float]) – How important the criteria are (usually on a 0-10 scale), in order of declaration.

  • **choices_to_ratings (tuple[float], optional) – Immediately assign ratings (dictionary values) to given choices (dictionary keys). The tuples must be in the same order of the criteria.

Raises

ValueError – If any given weight value is zero.

Examples

>>> import matrix
>>> m = matrix.Matrix()
>>> m.add_criteria('color', 'taste', weights=(5, 2))
>>> m
|        |   color |   taste |
|:-------|--------:|--------:|
| Weight |       5 |       2 |
>>> m = matrix.Matrix('apple', 'orange')
>>> m.add_criteria('color', 'taste', weights=(5, 2), apple=(4, 8), orange=(7, 5))
>>> m
|        |   color |   taste | Percentage        |
|:-------|--------:|--------:|:------------------|
| Weight |       5 |       2 |                   |
| apple  |       4 |       8 | 51.42857142857142 |
| orange |       7 |       5 | 64.28571428571429 |

Note

It is slower to add new choices using this method, compared to using the constructor or add_choices().