我有一个长度为500的numpy数组,并尝试获取其最大元素的位置。
> type(arr)
<type 'numpy.ndarray'>
> numpy.max(arr)
0.99841506 # the largest value is here the last one, so its position must be 499, but
> numpy.argmax(arr)
249 # argmax returns 249, which is 0.9814647
这个阵列出了什么问题?在其他情况下,argmax工作正常。 这是“异常”数组本身:
[ 0.88909795 0.88978061 0.89034673 0.89087944 0.89145257 0.89210397
0.89276644 0.89334441 0.89382041 0.89412578 0.89432752 0.8944299
0.89463225 0.89497062 0.89532122 0.89564772 0.8958474 0.89592464
0.89630575 0.89698798 0.89769293 0.89848076 0.89930387 0.90013392
0.90104787 0.90194464 0.90295569 0.9039833 0.9050346 0.90606623
0.90710517 0.90819266 0.90923895 0.91037811 0.91156073 0.91300442
0.91446512 0.91584151 0.91715882 0.91845024 0.91955421 0.92089298
0.92244761 0.92398027 0.92523805 0.92643114 0.92755521 0.92864628
0.92981656 0.93095717 0.93208001 0.93326082 0.93442172 0.93567889
0.93666403 0.93801784 0.93904143 0.94014266 0.94127314 0.94247457
0.94350104 0.94388245 0.9446991 0.94563049 0.94652052 0.94740291
0.94813891 0.94865294 0.94928902 0.94985706 0.95011467 0.95032619
0.95047542 0.95055906 0.95068319 0.95087543 0.95134286 0.95219489
0.95271328 0.95308582 0.95367633 0.95438522 0.95537771 0.95626897
0.95709159 0.95805329 0.95904842 0.96008088 0.96115256 0.96221983
0.96315547 0.9641299 0.96526232 0.96634076 0.9673133 0.96829591
0.9692317 0.97008387 0.97076741 0.97145813 0.97215305 0.97273013
0.97324447 0.97384943 0.97444085 0.97502589 0.97565676 0.9762706
0.97698153 0.9779038 0.97879313 0.97943701 0.98006739 0.98063262
0.98096896 0.98130123 0.98159047 0.98172486 0.98169341 0.98158367
0.98150869 0.9815271 0.98153536 0.98164806 0.98173003 0.98171431
0.98173717 0.98167403 0.98145793 0.98120804 0.98106709 0.98101609
0.98112061 0.98114241 0.98098263 0.98089001 0.98085913 0.98073206
0.98045551 0.98013516 0.9799087 0.97975682 0.97967519 0.97963055
0.97955903 0.97957455 0.97960247 0.97958315 0.97948352 0.9793838
0.97931257 0.97913527 0.97756488 0.97743783 0.97723032 0.9771425
0.97692371 0.97670625 0.97671619 0.9772266 0.97849404 0.97935737
0.98037385 0.98136674 0.98229204 0.98313426 0.98371021 0.98423502
0.98475514 0.98519817 0.9853992 0.98522209 0.98544847 0.98585939
0.9857425 0.9857368 0.98581936 0.98587366 0.98570029 0.98555498
0.98545724 0.98516041 0.98520702 0.98522651 0.98507088 0.98477696
0.98442745 0.98415864 0.98401446 0.98404856 0.98404806 0.98411621
0.98416166 0.98438146 0.98455107 0.98476666 0.98488303 0.98484396
0.98465454 0.98457754 0.9845227 0.98420963 0.98379581 0.98339187
0.98296063 0.98215673 0.9818166 0.98136827 0.98092174 0.98064912
0.98051665 0.98154758 0.98175672 0.98187866 0.98201024 0.98213502
0.98217471 0.98243727 0.98261784 0.98269089 0.98292136 0.98307152
0.98319756 0.98345249 0.98336651 0.98425455 0.98513982 0.98601273
0.98669306 0.98816828 0.98959878 0.99017499 0.99073479 0.99148809
0.99195023 0.99247333 0.99292418 0.99330445 0.99376024 0.99435036
0.99501503 0.99565791 0.9943401 0.99495361 0.99539686 0.99585094
0.99646274 0.99703564 0.99765937 0.99841506]
你可以解释一下吗?我不需要这个数组,但我想确保numpy.argmax的正确性。
PS。
Python 2.7.6(默认,2014年2月23日,01:28:31)[bCC 4.7.3] on linux2
numpy:1.8.0-r1答案 0 :(得分:2)
您的数组有250个元素。它们已编入[0]
到[249]
的索引。最后一个元素位于[249]
,正确找到了它。