numpy-ndarray

How to sort each row of a 3D numpy array by another 2D array?

↘锁芯ラ 提交于 2020-11-29 03:05:40
问题 I have a 2D numpy array of 2D points: np.random.seed(0) a = np.random.rand(3, 4, 2) # each value is a 2D point I would like to sort each row by the norm of every point norms = np.linalg.norm(a, axis=2) # shape(3, 4) indices = np.argsort(norms, axis=0) # indices of each sorted row Now I would like to create an array with the same shape and values as a . that will have each row of 2D points sorted by their norm. How can I achieve that? I tried variations of np.take & np.take_along_axis but with

How to sort each row of a 3D numpy array by another 2D array?

余生颓废 提交于 2020-11-29 03:04:01
问题 I have a 2D numpy array of 2D points: np.random.seed(0) a = np.random.rand(3, 4, 2) # each value is a 2D point I would like to sort each row by the norm of every point norms = np.linalg.norm(a, axis=2) # shape(3, 4) indices = np.argsort(norms, axis=0) # indices of each sorted row Now I would like to create an array with the same shape and values as a . that will have each row of 2D points sorted by their norm. How can I achieve that? I tried variations of np.take & np.take_along_axis but with

How to sort each row of a 3D numpy array by another 2D array?

非 Y 不嫁゛ 提交于 2020-11-29 03:02:53
问题 I have a 2D numpy array of 2D points: np.random.seed(0) a = np.random.rand(3, 4, 2) # each value is a 2D point I would like to sort each row by the norm of every point norms = np.linalg.norm(a, axis=2) # shape(3, 4) indices = np.argsort(norms, axis=0) # indices of each sorted row Now I would like to create an array with the same shape and values as a . that will have each row of 2D points sorted by their norm. How can I achieve that? I tried variations of np.take & np.take_along_axis but with

How to sort each row of a 3D numpy array by another 2D array?

只愿长相守 提交于 2020-11-29 03:01:34
问题 I have a 2D numpy array of 2D points: np.random.seed(0) a = np.random.rand(3, 4, 2) # each value is a 2D point I would like to sort each row by the norm of every point norms = np.linalg.norm(a, axis=2) # shape(3, 4) indices = np.argsort(norms, axis=0) # indices of each sorted row Now I would like to create an array with the same shape and values as a . that will have each row of 2D points sorted by their norm. How can I achieve that? I tried variations of np.take & np.take_along_axis but with