I have a one-dimensional array of the type numpy.ndarray and I want to know the index of it’s max entry. After finding the max, I used
peakIndex = numpy.where(myArray==max)
to find the peak’s index. But instead of the index, my script spits out
peakIndex = (array([1293]),)
I want my code to spit out just the integer 1293. How can I clean up the output?
Rather than using
numpy.where, you can usenumpy.argmax.numpy.argmaxreturns a single number, the flattened index of the first occurrence of the maximum value. IfmyArrayis multidimensional you might want to convert the flattened index to an index tuple: