gpt4 book ai didi

mysql - 缩放列中的值

转载 作者:行者123 更新时间:2023-11-29 07:03:50 26 4
gpt4 key购买 nike

我希望对我的数据进行特殊类型的缩放。

是否可以查询列中包含以下整数的数据库:

10
5
5
3
1
1
0
1
5
2
2

并通过查询生成以下表示:

1.0
0.8
0.8
0.6
0.2
0.2
0.0
1.0
0.8
0.4
0.4

因此最大值变为 1.0,0 保持为 0。然后我们有不包括 0 的唯一值集合,即 10, 5, 3, 2, 1。这个集合的长度是 5。倒数是 0.2 .然后我们列中的下一个最大值 5 变为 1 - 0.2 = 0.8。然后下一个最大值 3 变为 0.8-0.2 = 0.6,依此类推。

10->1.0, 5->0.8, 3->0.6, 2->0.4, 1->0.2, 0->0

或者您会建议执行查询的编程语言应该改为执行此缩放。

我是唯一一个查询数据库的人,我还没有选择我的数据库,但会使用开源或 SQL-Server 数据库。这种类型的缩放对我的应用程序非常重要,我将在不同的表上使用它。我将使用 Python3 进行编程。

编辑:SQL Server也是一个选项,还有开源数据库

最佳答案

我会推荐 PHP:

$myColumnArray = /* load mysql values here */;   
// order numbers smallest to largest
$uniqueElements = sort(array_unique($myColumnArray));
// calculate increment
$incriment = count($uniqueElements);
// go thru elements in orig array and replace with weighted value
foreach($myColumnArray as &$val){
// get position of element (i.e. "4th largest")
$position = array_search ($val, $uniqueElements);
// set it equal to weighted value
$val = $position * $increment;
}

关于mysql - 缩放列中的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8554724/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com