2
如何根據行的規範有效地對矩陣進行排序(使用numpy.ndarrays)?按功能排序(對稱)numpy二維數組。 (norm)
我想矩陣排序:
A = np.array(([ 10, 1, 6, 3 ],
[ 1,12, 2, 4 ],
[ 6, 2,14, 5 ],
[ 3, 4, 5, 9 ]))
其行的常態。
我現在所做的是創建一個規範列表並獲取該列表的索引列表,並根據該列表對矩陣進行排序。這是要走的路嗎?
indexlist = np.argsort(np.apply_along_axis(np.linalg.norm, 0, A))
#indexlist = array([3, 0, 1, 2])
然後我排序的列表。然後
sortedA = A[indexlist]
和對稱排序列表將
sym_sortedA = A[indexlist][:,indexlist]