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

点点圈 提交于 2020-06-08 19:02:27

问题


I was wondering if there is a built in normalisation function in flutter. That works like this

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

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

回答1:


I'm afraid there isn't one, but I've made what you're looking for manually:

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);


来源:https://stackoverflow.com/questions/57415765/how-to-normalise-data-between-1-1-in-flutter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!