擅长:python、mysql、java
<p>你可以用<a href="https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.max.html" rel="nofollow noreferrer">^{<cd1>}</a>。你知道吗</p>
<p><code>axis</code>关键字参数描述要沿哪个轴找到最大值。你知道吗</p>
<p><code>keepdims=True</code>允许您保留输入的维度。你知道吗</p>
<p>要获得列中最大值的索引,可以使用<a href="https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.argmax.html" rel="nofollow noreferrer">^{<cd4>}</a>函数。
也可以将<code>axis</code>参数传递给此函数,但没有keepdims选项。你知道吗</p>
<p>在这两个命令中,<code>axis=0</code>描述列,<code>axis=1</code>描述行。
标准值<code>axis=None</code>将搜索整个扁平数组中的最大值。你知道吗</p>
<p>示例:</p>
<pre><code>import numpy as np
A = np.asarray(
[[1, 2, 3, 4, 5],
[2, 4, 5, 8, 7],
[9, 8, 4, 5, 2],
[1, 2, 4, 7, 2],
[5, 9, 8, 7, 6],
[1, 2, 5, 4, 3]])
print(A)
max = A.max(axis=0, keepdims=True)
max_index = A.argmax(axis=0)
print('Max:', max)
print('Max Index:', max_index)
</code></pre>
<p>这张照片:</p>
<pre><code>[[1 2 3 4 5]
[2 4 5 8 7]
[9 8 4 5 2]
[1 2 4 7 2]
[5 9 8 7 6]
[1 2 5 4 3]]
Max: [[9 9 8 8 7]]
Max Index: [2 4 4 1 1]
</code></pre>