I am trying to adjust the order of an array that I created using the method in this post.
Basically depending on the row index of the array (where axis=0), the sub-element for that index has been removed (eg. if looking at index 1 then only elements 0 and 2 are present).
I need a way to position each element back into a row corresponding to its original index.
>>> a = array([[[222],[333]],
[[111],[333]],
[[111],[222]]])
Desired output:
>>> a = array([[[111],[111]],
[[222],[222]],
[[333],[333]]])
During my attempts I thought this might be getting close:
>>> n = a.shape[0]
>>> row_idx = np.nonzero(~np.eye(n,dtype=bool))[1].reshape(n,n-1) # dim0 indices
>>> print a.ravel() #flatten the array
[222, 333, 111, 333, 111, 222]
>>> print row_idx #somehow use these indices to reposition corresponding elements
[1 2 0 2 0 1]
I am not sure how to use row_idx to align the elements into corresponding rows, or if that is even an efficient way to do this?
Thanks!