median: throw an error for NaNs and empty arrays [#1142].

This also restricts median to arrays of real elements type.