我正在寻找最有效的方法来进行以下计算:
我有三个矩阵,像这样:
[[Brand1, operationCost], [Brand2, operationCost],...]
[[Brand1, maintenanceCost],[Brand2, maintenanceCost]...]
[[Brand1, replacementCost],[Brand2, replacementCost]...]
我需要计算每个品牌的总成本,运营+维护+更换。不可能所有的矩阵中都有相同的标记。得到另一个矩阵如下:
[[Brand1, totalCost],[Brand2, totalCost]...]
Numpy应该解决您的问题:
示例:
如果你想保持你的品牌与我会使用的变量相结合:
示例:
由于您似乎不使用python字典,这应该可以:
编辑:
不过,如果列表长度或品牌顺序发生变化,则不能使用上述代码。所以最好的解决办法是使用字典:
对于2.7版本之前的python:
此解决方案是纯Python(它不依赖于第三方依赖项),即使列表的长度不同,也应该可以工作:
相关问题 更多 >
编程相关推荐