Given I have two arrays:
array1 = np.array([np.nan,np.nan,np.nan,np.nan,2,np.nan,1,np.nan,np.nan,5,np.nan,np.nan,6,np.nan,10,9,np.nan])
array2 = np.array([np.nan,np.nan,np.nan,np.nan,45,np.nan,33,np.nan,np.nan,32,np.nan,np.nan,44,np.nan,10,53,np.nan])
I want to get array2 sorted in ascending order of array1 elements with same nan sequence:
[np.nan,np.nan,np.nan,np.nan,32,np.nan,10,np.nan,np.nan,33,np.nan,np.nan,44,np.nan,53,45,np.nan]
Seems I could use
np.argsort(array1) = [ 6 4 9 12 15 14 0 13 11 10 8 5 3 2 1 7 16] if there's a command to move elements in array2 like : put an element with index "6" to the first not nan place etc
Any ideas?
UPD1: I posted a related question How to replace elements of a numpy array from two different arrays for a case when we have to split the array for reordering