python numpy 模块argmax() out参数怎么使用?

import numpy as np

a = [[2, 9], [3, 6]]

res = np.argmax(a, axis=1, out=np.ones([2,2]))

print(res)

argmax(a, axis=None, out=None) 返回给定数组的最大索引,参数 a, axis 我都理解了,就是看不懂 out 的意思

文档是这么说的:

If provided, the result will be inserted into this array. It should be of the appropriate shape and dtype.

在上面的代码中,我的 outnp.ones([2,2]),但是结果报错了,说 out 和结果不匹配:

ValueError: output array does not match result of np.argmax.

百度没查到什么有用的讲解,来请教下,out 这个参数要怎么用?

阅读 7.2k
2 个回答

就是一个array填充

import numpy as np

a = [[2, 9], [3, 6], [4, 7]]

res = np.array([1, 2, 3])

np.argmax(a, axis=1, out=res)

print(res)

我也还没搞懂,等我搞懂了再来写答案

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题