【发布时间】:2017-06-06 19:19:30
【问题描述】:
假设我有一个 2x2 矩阵作为 PrimitiveDenseStore
pstore = [ 1 2
3 4 ]
是否可以根据给定的匿名函数映射所有这些值,例如
pstore.map(x -> x * x)
所以结果是
pstore = [ 1 4
9 16 ]
【问题讨论】:
假设我有一个 2x2 矩阵作为 PrimitiveDenseStore
pstore = [ 1 2
3 4 ]
是否可以根据给定的匿名函数映射所有这些值,例如
pstore.map(x -> x * x)
所以结果是
pstore = [ 1 4
9 16 ]
【问题讨论】:
好吧,我对 java 的 UnaryOperator 感到困惑,原来 ojAlgo 需要自己的功能接口 PrimitiveFunction.Unary
PrimitiveFunction.Unary square = arg -> arg * arg;
pstore.modifyAll(square);
【讨论】:
至少有 3 种选择供您“调查”:
pstore.loopAll(...);
pstore.modifyAll(...);
pstore.operateOnAll(...);
和/或你可以看看这些问题的答案:
Elementwise multiplication two matrices or PrimitiveDenseStores in ojAlgo
【讨论】: