ENH: compute mask in nanstd/nanmean only once