- sp.diags
# inputs:
[0.06896536 0.03290889 0.05405389 0.06451621 0.03508776 0.04255323
0.4 0.05714307 0.4 0.07407343 0.08610969 0.0253165 ]
print(sp.diags(r_inv))
# output: 对角矩阵,但是是稀疏的。
(0, 0) 0.06896536
(1, 1) 0.03290889
(2, 2) 0.05405389
(3, 3) 0.06451621
(4, 4) 0.035087757
(5, 5) 0.042553235
(6, 6) 0.4
(7, 7) 0.057143074
(8, 8) 0.4
(9, 9) 0.07407343
(10, 10) 0.08610969
(11, 11) 0.025316505
# 稀疏矩阵直接和原大小矩阵相乘
r_mat_inv.dot(features)
# ouput:
features.shape