I'm having real trouble with this. I have a three-dimensional numpy array, and I'd like to re-order it by a two-dimensional indexing array. In reality the arrays will be determined programatically and the three-dimensional array may be two or four-dimensioned, but to keep things simple, here's the desired outcome if both arrays were two-dimensional:
ph = np.array([[1,2,3], [3,2,1]])
ph_idx = np.array([[0,1,2], [2,1,0]])
for sub_dim_n, sub_dim_ph_idx in enumerate(ph_idx):
ph[sub_dim_n] = ph[sub_dim_n][sub_dim_ph_idx]
This makes the ph array into:
array([[1, 2, 3],
[1, 2, 3]])
Which is what I'd like. Could anyone please help if it's the same circumstance, but instead of ph, I have a three-dimensional array (psh), like:
psh = np.array(
[[[1,2,3]],
[[3,2,1]]]
)
Hope that's clear and please ask if it's not. Thanks in advance!
ph_idxin your three-dimensional case?[3, 2, 1]this time? Could you also provide an example wherephhas shape(2, 2, 3)?