如何在 flutter 中规范化 [-1, 1] 之间的数据

How to normalise data between [-1, 1] in flutter

我想知道flutter中是否有内置的归一化功能。像这样工作

List<int> array = [-105,24,66,-50,-49,2]

//Normalises to get numbers between -1 and 1
List<double> normalised = array.normalise(-1,1) 

恐怕没有,但我已经手动制作了您要找的东西:

import 'dart:math';

List<int> array = [-105, 24, 66, -50, -49, 2];
final lower = array.reduce(min);
final upper = array.reduce(max);
final List<double> normalized = [];

array.forEach((element) => element < 0
    ? normalized.add(-(element / lower))
    : normalized.add(element / upper));

print(normalized);