class documentation
简单的矩阵数据类型。
当然,Python 有更高级的矩阵数据类型(例如,Numeric Python 的 ndarray 数据类型),而这个实现并不打算与它们竞争。这种数据类型的唯一作用是提供一个方便的接口,用于处理由 Graph 对象返回的矩阵(例如,允许在邻接矩阵的情况下使用元组进行索引等)。
| 类方法 | |
创建一个填充给定值的矩阵 |
| 类方法 | |
创建一个单位矩阵。 |
| 类方法 | |
创建一个填充零的矩阵。 |
| 方法 | __add__ |
将给定值添加到矩阵中。 |
| 方法 | __eq__ |
检查给定矩阵是否等于另一个矩阵 |
| 方法 | __getitem__ |
返回矩阵中的单个元素、一行或一列 |
| 方法 | __hash__ |
返回矩阵的哈希值。 |
| 方法 | __iadd__ |
矩阵或标量的原地加法。 |
| 方法 | __init__ |
初始化一个矩阵。 |
| 方法 | __isub__ |
矩阵或标量的原地减法。 |
| 方法 | __iter__ |
支持迭代。 |
| 方法 | __len__ |
返回矩阵中的行数。 |
| 方法 | __ne__ |
检查给定矩阵是否不等于另一个矩阵 |
| 方法 | __plot__ |
将矩阵绘制到给定的Cairo上下文或matplotlib Axes上。 |
| 方法 | __repr__ |
未记录 |
| 方法 | __setitem__ |
设置矩阵的单个项目、一行或一列 |
| 方法 | __str__ |
未记录 |
| 方法 | __sub__ |
从矩阵中减去给定的值。 |
| 方法 | max |
返回矩阵沿给定维度的最大值 |
| 方法 | min |
返回矩阵沿给定维度的最小值 |
| 实例变量 | data |
未记录 |
| 属性 | shape |
返回矩阵的形状作为一个元组 |
| 方法 | _get |
返回存储在矩阵中的数据作为列表的列表 |
| 方法 | _set |
设置存储在矩阵中的数据 |
| 实例变量 | _data |
未记录 |
| 实例变量 | _ncol |
未记录 |
| 实例变量 | _nrow |
未记录 |
返回矩阵中的单个项目、一行或一列
| 参数 | |
| i | 如果是一个整数,返回第 i 行作为一个列表。如果是一个切片,返回相应的行作为另一个 Matrix 对象。如果是一个2元组,元组的第一个元素用于选择行,第二个元素用于选择列。 |
将矩阵绘制到给定的Cairo上下文或matplotlib Axes。
除了通常的自解释绘图参数(context, bbox, palette),它还接受以下关键字参数:
- style: the style of the plot. boolean is useful for plotting matrices with boolean (True/False or 0/1) values: False will be shown with a white box and True with a black box. palette uses the given palette to represent numbers by colors, the minimum will be assigned to palette color index 0 and the maximum will be assigned to the length of the palette. None draws transparent cell backgrounds only. The default style is boolean (but it may change in the future). None values in the matrix are treated specially in both cases: nothing is drawn in the cell corresponding to None.
- square: whether the cells of the matrix should be square or not. Default is True.
- grid_width: line width of the grid shown on the matrix. If zero or negative, the grid is turned off. The grid is also turned off if the size of a cell is less than three times the given line width. Default is 1. Fractional widths are also allowed.
- border_width: line width of the border drawn around the matrix. If zero or negative, the border is turned off. Default is 1.
- row_names: the names of the rows
- col_names: the names of the columns.
- values: values to be displayed in the cells. If None or False, no values are displayed. If True, the values come from the matrix being plotted. If it is another matrix, the values of that matrix are shown in the cells. In this case, the shape of the value matrix must match the shape of the matrix being plotted.
- value_format: a format string or a callable that specifies how the values should be plotted. If it is a callable, it must be a function that expects a single value and returns a string. Example: "%#.2f" for floating-point numbers with always exactly two digits after the decimal point. See the Python documentation of the % operator for details on the format string. If the format string is not given, it defaults to the str function.
如果只给出了行名或列名,并且矩阵是方形的,则相同的名称将用于列名和行名。
设置矩阵的单个项目、一行或一列
| 参数 | |
| i | 如果是一个整数,将第i行设置为一个列表。如果是一个切片,从另一个Matrix对象中设置相应的行。如果是一个2元组,元组的第一个元素用于选择行,第二个元素用于选择列。 |
| value | 新值 |