我想从 suitCounts 中选择 maxsuit 中指定的第 n 个元素。我确实广播了 maxsuit 数组,所以我得到了一个结果,但不是想要的。任何我在概念上做错的建议都值得赞赏。我不明白 的结果np.choose(self.maxsuit[:,:,None]-1, self.suitCounts)
,这不是我想要的。
>>> self.maxsuit
Out[38]:
array([[3, 3],
[1, 1],
[1, 1]], dtype=int64)
>>> self.maxsuit[:,:,None]-1
Out[33]:
array([[[2],
[2]],
[[0],
[0]],
[[0],
[0]]], dtype=int64)
>>> self.suitCounts
Out[34]:
array([[[2, 1, 3, 0],
[1, 0, 3, 0]],
[[4, 1, 2, 0],
[3, 0, 3, 0]],
[[2, 2, 0, 0],
[1, 1, 1, 0]]])
>>> np.choose(self.maxsuit[:,:,None]-1, self.suitCounts)
Out[35]:
array([[[2, 2, 0, 0],
[1, 1, 1, 0]],
[[2, 1, 3, 0],
[1, 0, 3, 0]],
[[2, 1, 3, 0],
[1, 0, 3, 0]]])
期望的结果是:
[[3,3],[4,3],[2,1]]