When I call tf.mean, I get an inaccurate result. The result is only slightly off, so I think there may be some kind of rounding issue. For example, for an array with numbers from 0 through 100,000,000 the mean comes out to 50,000,040 instead of 50,000,000.
I made sure to set the data type to float32 when creating the tensor. I also tried implementing similar code with python Tensorflow with reduce_mean, which gave the correct result.
const tf = require('@tensorflow/tfjs');
require('@tensorflow/tfjs-node');
const dataset = [];
for (let i = 0; i <= 100000000; i++) {
dataset.push(i);
}
let tArr = tf.tensor1d(dataset, 'float32');
let tAvg = tArr.mean();
let avg = tAvg.dataSync()[0];
console.log(avg) // 50000040
The average should be 50,000,000 but instead I got 50,000,040.