数组中对某项相同的值进行求和计算
$arr = array(15) {
[0]=>
array(9) {
["lppt"]=>
string(4) "LP1 "
["fg_type"]=>
string(5) "ECU "
["customer_no"]=>
string(4) "A001"
["etype1"]=>
string(3) "DIG"
["RevDegree"]=>
string(2) "S "
["item1"]=>
float(8810)
["rs1"]=>
float(5787788.527)
["item2"]=>
float(8928)
["rs2"]=>
float(5865309.4176)
}
[1]=>
array(9) {
["lppt"]=>
string(4) "LP1 "
["fg_type"]=>
string(3) "ECU"
["customer_no"]=>
string(4) "A001"
["etype1"]=>
string(3) "MPI"
["RevDegree"]=>
string(1) "B"
["item1"]=>
float(0)
["rs1"]=>
float(0)
["item2"]=>
float(0)
["rs2"]=>
float(0)
}
[2]=>
array(9) {
["lppt"]=>
string(4) "LP1 "
["fg_type"]=>
string(4) "ECU "
["customer_no"]=>
string(4) "A001"
["etype1"]=>
string(3) "MPI"
["RevDegree"]=>
string(2) "S "
["item1"]=>
float(63485)
["rs1"]=>
float(23211270.7503)
["item2"]=>
float(71973)
["rs2"]=>
float(26689668.0654)
}
[3]=>
array(9) {
["lppt"]=>
string(4) "LP1 "
["fg_type"]=>
string(4) "ECU "
["customer_no"]=>
string(4) "A002"
["etype1"]=>
string(3) "MPI"
["RevDegree"]=>
string(2) "S "
["item1"]=>
float(4810)
["rs1"]=>
float(2329072.60146)
["item2"]=>
float(5855)
["rs2"]=>
float(2783605.29921)
}
[4]=>
array(9) {
["lppt"]=>
string(4) "LP1 "
["fg_type"]=>
string(5) "ECU "
["customer_no"]=>
string(4) "A004"
["etype1"]=>
string(3) "MPI"
["RevDegree"]=>
string(2) "S "
["item1"]=>
float(1716)
["rs1"]=>
float(652004.847)
["item2"]=>
float(1711)
["rs2"]=>
float(647801.6757)
}
[5]=>
array(9) {
["lppt"]=>
string(4) "LP2 "
["fg_type"]=>
string(3) "ECU"
["customer_no"]=>
string(4) "A001"
["etype1"]=>
string(3) "MPI"
["RevDegree"]=>
string(1) "B"
["item1"]=>
float(0)
["rs1"]=>
float(0)
["item2"]=>
float(0)
["rs2"]=>
float(0)
}
};求当fg_type项相同时,针对item1,item2,rs1,rs2项的求和,并将求得的结果放在此数组后。
相关推荐
JS数组求和的常用方法实例小结
主要介绍了JS数组求和的常用方法,结合实例形式总结分析了javascript常见的遍历、循环、归并等数组操作相关技巧,需要的朋友可以参考下
解决vue 表格table列求和的问题
今天小编就为大家分享一篇解决vue 表格table列求和的问题,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
C++数组求和技巧[代码]
本文介绍了C++中利用numeric库的accumulate函数简化数组求和的方法。accumulate函数通过指定元素范围的首地址和末地址,以及累加初值,可以快速计算数组的和。文章提供了具体的代码示例,并对比了传统循环求和与accumulate函数的使用方式,指出两者各有优势,但底层效率上循环求和更优。此外,还提醒读者注意accumulate函数所在的头文件为<numeric>。
python 按不同维度求和,最值,均值的实例
当变量维数加大时很难想象是怎样按不同维度求和的,高清楚一个,其他的应该就很清楚了,什么都不说了,上例子,例子一看便明白….. a=range(27) a=np.array(a) a=np.reshape(a,[3,3,3]) 输出a的结果是: array([[[ 0, 1, 2], [ 3, 4, 5], [ 6, 7, 8]], [[ 9, 10, 11], [12, 13, 14], [15, 16, 17]], [[18, 19, 20], [21, 22, 23], [24, 25, 26]]]) 我们来看看 aa=np.sum(a,-1)的输出:
解决Numpy中sum函数求和结果维度的问题
今天小编大家分享一篇解决Numpy中sum函数求和结果维度的问题,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧


基础编程
