scipy.sparse.coo_matrix疎行列記憶データ

# Constructing an empty matrix
from scipy.sparse import coo_matrix
coo_matrix((3, 4), dtype=np.int8).toarray()
アレイ([0、0、0、0]、
       [0、0、0、0]、
       [0、0、0、0]、DTYPE = INT8)
row  = np.array([0, 3, 1, 0])
col  = np.array([0, 3, 1, 2])
data = np.array([4, 5, 7, 9])
coo_matrix((data, (row, col)), shape=(4, 4)).toarray()
アレイ([[4,0、9、0]、
       [0、7、0、0]、
       [0、0、0、0]、
       [0、0、0、5])
row  = np.array([0, 0, 1, 3, 1, 0, 0])
col  = np.array([0, 2, 1, 3, 1, 0, 0])
data = np.array([1, 1, 1, 1, 1, 1, 1])
coo = coo_matrix((data, (row, col)), shape=(4, 4))
# Duplicate indices are maintained until implicitly or explicitly summed
coo.toarray()
アレイ([3、0、1、0]、
       [0、2、0、0]、
       [0、0、0、0]、
       [0、0、0、1]])
公開された128元の記事 ウォン称賛90 ビュー4889

おすすめ

転載: blog.csdn.net/weixin_45405128/article/details/102604619