OjAlgo : Is there a way to add/subtract a double from all elements of a PrimitiveDenseStore in ojAlgo?

我怕爱的太早我们不能终老 提交于 2019-12-12 01:20:06

问题


Looking for a function to add/subtract a double from all elements of a matrix or dense store.


回答1:


Some alternatives:

    matrixA.operateOnAll(ADD.second(scalarB)).supplyTo(matrixC);

    matrixC.fillMatching(matrixA, ADD, scalarB);

    matrixC.modifyAll(ADD.second(scalarB));

    matrixA.passMatching((from, i, j, to) -> {
        to.set(i, j, from.doubleValue(i, j) + scalarB);
    }, matrixC);

Where ADD comes from a static import (org.ojalgo.function.PrimitiveFunction) and the call to the second(...) method set/locks the second argument of the binary "add" function turning it into a unary function that you can pass to the operateOnAll(...) or modifyAll(...) methods.



来源:https://stackoverflow.com/questions/41675095/ojalgo-is-there-a-way-to-add-subtract-a-double-from-all-elements-of-a-primitiv

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!