鍍金池/ 問答/數(shù)據(jù)分析&挖掘  Python/ python numpy 模塊argmax() out參數(shù)怎么使用?

python numpy 模塊argmax() out參數(shù)怎么使用?

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) 返回給定數(shù)組的最大索引,參數(shù) 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]),但是結(jié)果報(bào)錯(cuò)了,說 out 和結(jié)果不匹配:

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

百度沒查到什么有用的講解,來請(qǐng)教下,out 這個(gè)參數(shù)要怎么用?

回答
編輯回答
孤客

就是一個(gè)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)

2017年8月18日 08:51
編輯回答
兮顏

我也還沒搞懂,等我搞懂了再來寫答案

2017年10月1日 03:52