Given a numpy array (or pandas dataframe) like this:
import numpy as np a = np.array([ [1, 1, 1, 0.5, np.nan, np.nan, np.nan], [1, 1,
If all nan values have been sorted to the end of each row, you can do something like this:
nan
(~np.isnan(a)).sum(axis = 1) - 1 # array([3, 2, 6, 3, 0, 3])