What does this peace of python code
row = R[i,]
j = numpy.nonzero(row == max(row))[0][0]
do, assuming this output:
command # output of python
----------------------------------
R.shape # (224, 24)
type(R) # <type 'numpy.ndarray'>
type(row) # <type 'numpy.ndarray'>
type(j) # <type 'numpy.int64'>
(I'll provide more information if required, to answer my question.)
Sorry, I used two times the variable i
. I changed that in the question!
The two lines appear to be a roundabout way of saying j = np.argmax(R[i])
, i.e. find the column index of the largest element in the i
-th row of R
, and store the result in j
.
Perhaps an example will help:
In []: R= arange(12).reshape(4, 3)
In []: R
Out[]:
array([[ 0, 1, 2],
[ 3, 4, 5],
[ 6, 7, 8],
[ 9, 10, 11]])
In []: i= 1
In []: row= R[i, ]
In []: row
Out[]: array([3, 4, 5])
In []: j= nonzero(row== max(row))[0][0]
In []: j
Out[]: 2
Thus the j
is the index of the maximum element in the i
th row of R
. So
In []: R[i, j]
Out[]: 5
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With