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.
在上面的代码中,我的 out
是 np.ones([2,2])
,但是结果报错了,说 out
和结果不匹配:
ValueError: output array does not match result of np.argmax.
百度没查到什么有用的讲解,来请教下,out
这个参数要怎么用?
就是一个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)