我想用numpy數組初始化一個稀疏矩陣。所述numpy的數組包含的NaN爲零我的程序,如以下初始稀疏矩陣的代碼:用numpy.NaN初始化一個scipy.sparse矩陣的最快方法是什麼?
a= np.array([[np.NaN,np.NaN,10]])
zero_a= np.array([[0,0,10]])
spr_a = lil_matrix(a)
zero_spr_a = lil_matrix(zero_a)
print repr(spr_a)
print repr(zero_spr_a)
輸出是
1x3 sparse matrix of type 'type 'numpy.float64'' with 3 stored elements in LInked List format 1x3 sparse matrix of type 'type 'numpy.int64'' with 1 stored elements in LInked List format
用於與0陣列中,這裏只有1存儲在稀疏元件矩陣。但有3個元素存儲在NaN數組中,如何將NaN作爲scipy矩陣的零處理?