您的位置:首页 > 编程语言 > Python开发

python Sparse matrices 单位矩阵

2016-02-16 09:44 246 查看
identity(n[, dtype, format]) Identity matrix in sparse format Returns an identity matrix with shape (n,n) using a given sparse format and dtype.

创建n X n单位矩阵。

format:

bsr_matrix(arg1[, shape, dtype, copy, blocksize])
Block Sparse Row matrix This can be instantiated in several ways: bsr_matrix(D, [blocksize=(R,C)]) where D is a dense matrix or 2-D ndarray.

coo_matrix(arg1[, shape, dtype, copy]) A sparse matrix in COOrdinate format.

csc_matrix(arg1[, shape, dtype, copy]) Compressed Sparse Column matrix This can be instantiated in several ways: csc_matrix(D) with a dense matrix or rank-2 ndarray D csc_matrix(S) with another sparse matrix S (equivalent
to S.tocsc()) csc_matrix((M, N), [dtype]) to construct an empty matrix with shape (M, N) dtype is optional, defaulting to dtype=’d’.

csr_matrix(arg1[, shape, dtype, copy]) Compressed Sparse Row matrix This can be instantiated in several ways: csr_matrix(D) with a dense matrix or rank-2 ndarray D csr_matrix(S) with another sparse matrix S (equivalent to
S.tocsr()) csr_matrix((M, N), [dtype]) to construct an empty matrix with shape (M, N) dtype is optional, defaulting to dtype=’d’.

dia_matrix(arg1[, shape, dtype, copy]) Sparse matrix with DIAgonal storage This can be instantiated in several ways: dia_matrix(D) with a dense matrix dia_matrix(S) with another sparse matrix S (equivalent to S.todia())
dia_matrix((M, N), [dtype]) to construct an empty matrix with shape (M, N), dtype is optional, defaulting to dtype=’d’.

dok_matrix(arg1[, shape, dtype, copy]) Dictionary Of Keys based sparse matrix.

lil_matrix(arg1[, shape, dtype, copy]) Row-based linked list sparse matrix This is a structure for constructing sparse matrices incrementally.

spmatrix([maxprint]) This class provides a base class for all sparse matrices.

======================================================================================

Examples

>>> from scipy.sparse import identity

>>> identity(3).toarray()

array([[ 1., 0., 0.],

[ 0., 1., 0.],

[ 0., 0., 1.]])

>>> identity(3, dtype='int8', format='dia')

<3x3 sparse matrix of type '<type 'numpy.int8'>'

with 3 stored elements (1 diagonals) in DIAgonal format>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: