本文簡要介紹 python 語言中 scipy.sparse.dok_array
的用法。
用法:
class scipy.sparse.dok_array(arg1, shape=None, dtype=None, copy=False)#
基於字典的鍵的稀疏數組。
這是一種用於增量構造稀疏數組的有效結構。
- dok_array(D)
其中 D 是二維 ndarray
- dok_array(S)
與另一個稀疏數組或矩陣 S (相當於 S.todok())
- dok_array((M,N), [dtype])
創建具有初始形狀 (M,N) 的數組 dtype 是可選的,默認為 dtype='d'
這可以通過多種方式實例化::
注意:
稀疏數組可用於算術運算:它們支持加法、減法、乘法、除法和矩陣冪。
允許對各個元素進行有效的 O(1) 訪問。
不允許重複。
構建後可以有效地轉換為coo_array。
例子:
>>> import numpy as np >>> from scipy.sparse import dok_array >>> S = dok_array((5, 5), dtype=np.float32) >>> for i in range(5): ... for j in range(5): ... S[i, j] = i + j # Update element
相關用法
- Python SciPy sparse.dok_matrix用法及代碼示例
- Python SciPy sparse.dia_array用法及代碼示例
- Python SciPy sparse.dia_matrix用法及代碼示例
- Python SciPy sparse.diags用法及代碼示例
- Python SciPy sparse.diags_array用法及代碼示例
- Python SciPy sparse.isspmatrix用法及代碼示例
- Python SciPy sparse.save_npz用法及代碼示例
- Python SciPy sparse.issparse用法及代碼示例
- Python SciPy sparse.coo_matrix用法及代碼示例
- Python SciPy sparse.isspmatrix_csc用法及代碼示例
- Python SciPy sparse.isspmatrix_csr用法及代碼示例
- Python SciPy sparse.tril用法及代碼示例
- Python SciPy sparse.coo_array用法及代碼示例
- Python SciPy sparse.bmat用法及代碼示例
- Python SciPy sparse.hstack用法及代碼示例
- Python SciPy sparse.rand用法及代碼示例
- Python SciPy sparse.find用法及代碼示例
- Python SciPy sparse.isspmatrix_dia用法及代碼示例
- Python SciPy sparse.isspmatrix_lil用法及代碼示例
- Python SciPy sparse.csc_matrix用法及代碼示例
- Python SciPy sparse.block_diag用法及代碼示例
- Python SciPy sparse.vstack用法及代碼示例
- Python SciPy sparse.kron用法及代碼示例
- Python SciPy sparse.random用法及代碼示例
- Python SciPy sparse.identity用法及代碼示例
注:本文由純淨天空篩選整理自scipy.org大神的英文原創作品 scipy.sparse.dok_array。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。