本文介绍了如何在flutter中的[-1,1]之间对数据进行规范化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道在flutter中是否有内置的归一化功能。像这样
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)
推荐答案
恐怕没有人,但是我已经手动完成了您要寻找的东西:
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);
这篇关于如何在flutter中的[-1,1]之间对数据进行规范化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!