Is it possible to use numpy.nanargmin
, so that it returns numpy.nan
, on columns where there are only nans in them. Right now, it raises a ValueError
, when that happens. And i cant use numpy.argmin
, since that will fail when there are only a few nans in the column.
http://docs.scipy.org/doc/numpy/reference/generated/numpy.nanargmin.html says that the ValueError
is raised for all-nan slices. In that case, i want it to return numpy.nan (just to further mask the "non-data" with nans)
this next bit does this, but is super-slow and not really pythonic:
for i in range(R.shape[0]):
bestindex = numpy.nanargmin(R[i,:])
if(numpy.isnan(bestindex)):
bestepsilons[i]=numpy.nan
else:
bestepsilons[i]=epsilon[bestindex]
This next bit works too, but only if no all-nan columns are involved:
ar = numpy.nanargmin(R, axis=1)
bestepsilons = epsilon[ar]
So ideally i would want this last bit to work with all-nan columns as well