は、同じ行を持ちますが順序が違う2つのnumpy ndarraysです。関数g1を行単位で適用すると、同じ結果が別の順序で返されることが予想されます。しかし、そうではありません。numpy apply_along_axisが機能しないのはなぜですか?
g1(x):
return max(0, (x[0] - 1)**2 + (x[1] - 1)**2 - 1.05**2)
Case1:
sol1 = np.array(
[
[0, 0],
[1, 1],
[0, 1],
[1, 0],
[0.2, 0.7],
[0.5, 0.5],
[0.75, 0],
[0.25, 0.8],
[0.5, 0.6],
[0.2, 0.7],
]
)
v = numpy.apply_along_axis(g1, 1, sol1)
This produce: [ 0.8975, 0., 0., 0., 0., 0., 0., 0., 0., 0.] as expected.
Case2:
# The same array with rows shuffled.
sols = numpy.array(
[
[0, 1],
[0.2, 0.7],
[0.5, 0.5],
[0.75, 0],
[0.2, 0.7],
[1, 0],
[0.25, 0.8],
[0.5, 0.6],
[0, 0],
[1, 1],
]
)
v = numpy.apply_along_axis(g1, 1, sols)
This produces: [ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.] which is wrong.
Should be: [ 0., 0., 0., 0., 0., 0., 0., 0., 0.8975, 0.]
私のシステムでは、次のとおりです。 numpyの:1.13.1: のpython:3.6.2: Win10プロ: conda:あなたの計算を再作成4.3.27
おかげ
すなわち、 '(0.0、...)最大' のすべてのケースでfloatを返す試してみてください。 – hpaulj
これは両方のケースでうまくいきました。ありがとうございました。私はちょうどそれがすべての違いを作った理由を理解しようとしています – Christie