Added a recursive function to replace nan, inf and -inf in nested list.