class documentation

class Matrix: (source)

构造函数: Matrix(data)

查看层次结构

简单的矩阵数据类型。

当然,Python 有更高级的矩阵数据类型(例如,Numeric Python 的 ndarray 数据类型),而这个实现并不打算与它们竞争。这种数据类型的唯一作用是提供一个方便的接口,用于处理由 Graph 对象返回的矩阵(例如,允许在邻接矩阵的情况下使用元组进行索引等)。

类方法 Fill 创建一个填充给定值的矩阵
类方法 Identity 创建一个单位矩阵。
类方法 Zero 创建一个填充零的矩阵。
方法 __add__ 将给定值添加到矩阵中。
方法 __eq__ 检查给定矩阵是否等于另一个矩阵
方法 __getitem__ 返回矩阵中的单个元素、一行或一列
方法 __hash__ 返回矩阵的哈希值。
方法 __iadd__ 矩阵或标量的原地加法。
方法 __init__ 初始化一个矩阵。
方法 __isub__ 矩阵或标量的原地减法。
方法 __iter__ 支持迭代。
方法 __len__ 返回矩阵中的行数。
方法 __ne__ 检查给定矩阵是否不等于另一个矩阵
方法 __plot__ 将矩阵绘制到给定的Cairo上下文或matplotlib Axes上。
方法 __repr__ 未记录
方法 __setitem__ 设置矩阵的单个项目、一行或一列
方法 __str__ 未记录
方法 __sub__ 从矩阵中减去给定的值。
方法 max 返回矩阵沿给定维度的最大值
方法 min 返回矩阵沿给定维度的最小值
实例变量 data 未记录
属性 shape 返回矩阵的形状作为一个元组
方法 _get_data 返回存储在矩阵中的数据作为列表的列表
方法 _set_data 设置存储在矩阵中的数据
实例变量 _data 未记录
实例变量 _ncol 未记录
实例变量 _nrow 未记录
@classmethod
def Fill(cls, value, *args): (source)

创建一个用给定值填充的矩阵

参数
value要使用的值
*args未记录
shape矩阵的形状。可以是一个整数、两个整数或一个元组。如果这里给出一个整数,则假定矩阵是方形的。
@classmethod
def Identity(cls, *args): (source)

创建一个单位矩阵。

参数
*args未记录
shape矩阵的形状。可以是一个整数、两个整数或一个元组。如果这里给出一个整数,则假定矩阵是方形的。
@classmethod
def Zero(cls, *args): (source)

创建一个填充零的矩阵。

参数
*args未记录
shape矩阵的形状。可以是一个整数、两个整数或一个元组。如果这里给出一个整数,则假定矩阵是方形的。
def __add__(self, other): (source)

将给定值添加到矩阵中。

参数
other可以是一个标量或矩阵。标量将被添加到矩阵的每个元素中。矩阵将按元素相加。
返回
结果矩阵
def __eq__(self, other): (source)

检查给定的矩阵是否等于另一个矩阵

def __getitem__(self, i): (source)

返回矩阵中的单个项目、一行或一列

参数
i如果是一个整数,返回第 i 行作为一个列表。如果是一个切片,返回相应的行作为另一个 Matrix 对象。如果是一个2元组,元组的第一个元素用于选择行,第二个元素用于选择列。
def __hash__(self): (source)

返回矩阵的哈希值。

def __iadd__(self, other): (source)

就地添加矩阵或标量。

def __init__(self, data=None): (source)

初始化一个矩阵。

参数
data矩阵的元素作为列表的列表,或 None 以创建一个 0x0 矩阵。
def __isub__(self, other): (source)

矩阵或标量的就地减法。

def __iter__(self): (source)

支持迭代。

这实际上是通过生成器实现的,因此不需要单独的迭代器类。生成器返回矩阵中行的副本作为列表,以避免干扰内部结构。可以随意对副本进行任何操作,更改不会反映在原始矩阵中。

def __len__(self): (source)

返回矩阵中的行数。

def __ne__(self, other): (source)

检查给定的矩阵是否不等于另一个矩阵

def __plot__(self, backend, context, **kwds): (source)

将矩阵绘制到给定的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.

如果只给出了行名或列名,并且矩阵是方形的,则相同的名称将用于列名和行名。

def __repr__(self): (source)

未记录

def __setitem__(self, i, value): (source)

设置矩阵的单个项目、一行或一列

参数
i如果是一个整数,将第i行设置为一个列表。如果是一个切片,从另一个Matrix对象中设置相应的行。如果是一个2元组,元组的第一个元素用于选择行,第二个元素用于选择列。
value新值
def __str__(self): (source)

未记录

def __sub__(self, other): (source)

从矩阵中减去给定的值。

参数
other可以是一个标量或矩阵。标量将从矩阵的每个元素中减去。矩阵将按元素逐个相减。
返回
结果矩阵
def max(self, dim=None): (source)

返回矩阵沿给定维度的最大值

参数
dim维度。0表示确定列的最大值,1表示确定行的最大值。如果None,则返回全局最大值。
def min(self, dim=None): (source)

返回矩阵沿给定维度的最小值

参数
dim维度。0表示确定列的最小值,1表示确定行的最小值。如果None,则返回全局最小值。

未记录

返回矩阵的形状作为一个元组

def _get_data(self): (source)

返回存储在矩阵中的数据作为列表的列表

def _set_data(self, data=None): (source)

设置存储在矩阵中的数据

未记录

未记录

未记录