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

后端 未结 1 348
孤独总比滥情好
孤独总比滥情好 2021-01-20 21:00

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

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

//Normalises t         


        
1条回答
  •  时光说笑
    2021-01-20 21:42

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

    import 'dart:math';
    
    List array = [-105, 24, 66, -50, -49, 2];
    final lower = array.reduce(min);
    final upper = array.reduce(max);
    final List normalized = [];
    
    array.forEach((element) => element < 0
        ? normalized.add(-(element / lower))
        : normalized.add(element / upper));
    
    print(normalized);
    

    0 讨论(0)
提交回复
热议问题