The second suggestion was also only a theoretical one. Using the whole dataset as one large batch is usually not done anymore. However this example should work and it does not make sense to me that it produces NaN