2010-09-12 48 views

Trả lời

8

Sử dụng scipy.sparse.spdiags (rất nhiều thứ và do đó có thể gây nhầm lẫn, ban đầu), scipy.sparse.dia_matrix và/hoặc scipy.sparse.lil_diags. (tùy thuộc vào số format bạn muốn ma trận thưa thớt trong ...)

Ví dụ: sử dụng spdiags:

import numpy as np 
import scipy as sp 
import scipy.sparse 

x = np.arange(10) 

# "0" here indicates the main diagonal... 
# "y" will be a dia_matrix type of sparse array, by default 
y = sp.sparse.spdiags(x, 0, x.size, x.size) 
1

Sử dụng các module scipy.sparse,

p = sparse.dia_matrix(1.0/np.array(x), shape=(len(x), len(x))); 
Các vấn đề liên quan