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>
创建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>
相关文章推荐
- python小点心--Event
- 深入解读Python解析XML的几种方式
- python(3)-内置函数2
- Atitit.sql ast 表达式 语法树 语法 解析原理与实现 java php c#.net js python
- Atitit.sql ast 表达式 语法树 语法 解析原理与实现 java php c#.net js python
- Atitit.sql ast 表达式 语法树 语法 解析原理与实现 java php c#.net js python
- 我的Mac之路(1)—— 安装虚拟机,以及打造VIM IDE for Python
- python语法学习
- 深入解读Python解析XML的几种方式
- bpython 功能强大的Python shell
- 十条建议帮你提高Python编程效率
- 轻松实现python搭建微信公众平台
- python实现红包裂变算法
- Python实现快速排序和插入排序算法及自定义排序的示例
- Python的GUI框架PySide的安装配置教程
- Python:__slots__用法
- 转 python常用代码
- python学习day day up
- 非常全面到位的介绍与源代码地址 :Python 网页爬虫 & 文本处理 & 科学计算 & 机器学习 & 数据挖掘兵器谱
- python实现快速排序