Leon4gr45's picture
Upload folder using huggingface_hub (part 10)
25e5703 verified
Raw
History Blame Contribute Delete
554 Bytes
'use strict'
module.exports = normalize;
function normalize (arr, dim) {
if (!arr || arr.length == null) throw Error('Argument should be an array')
if (dim == null) dim = 1
else dim = Math.floor(dim)
var bounds = Array(dim * 2)
for (var offset = 0; offset < dim; offset++) {
var max = -Infinity, min = Infinity, i = offset, l = arr.length;
for (; i < l; i+=dim) {
if (arr[i] > max) max = arr[i];
if (arr[i] < min) min = arr[i];
}
bounds[offset] = min
bounds[dim + offset] = max
}
return bounds;
}