<div class="gmail_quote">On 13 September 2012 21:16, Bala subramanian <span dir="ltr"><<a href="mailto:bala.biophysics@gmail.com" target="_blank">bala.biophysics@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Friends,<br>
I have a 2D matrix (a numpy array) and i am looping over each row in<br>
the matrix. I would like to know how i can find the index of each<br>
element in a while looping a row. Is there any function in numpy.<br></blockquote><div><br></div><div>Your question could mean several things. Could you post a small piece of example code and clarify what it is you're unable to do?</div>
<div><br></div><div>Here's an example that loops over all elements of a 2D Matrix:</div><div><br></div><div><div>>>> import numpy</div><div>>>> M = numpy.array([[1, 1], [2, 3], [5, 8]])</div><div>>>> M</div>
<div>array([[1, 1],</div><div>       [2, 3],</div><div>       [5, 8]])</div><div>>>> numrows, numcols = M.shape</div><div>>>> for i in range(numrows):</div><div>...   for j in range(numcols):</div><div>...      print M[i, j]</div>
<div>... </div><div>1</div><div>1</div><div>2</div><div>3</div><div>5</div><div>8</div></div><div><br></div><div>Oscar</div></div>