Computer Science, asked by Asamsaj7252, 6 months ago

Consider an (8, 8) shape NumPy array. What is the index (x,y) of the 50th element? Note: For counting the elements go row-wise. For example, in the array, [[1, 5, 9], [3, 0, 2]] the 5th element would be '0'.

Answers

Answered by akshaykumarsharmaaks
19

Answer:

np.unravel_index(49, (8,8))

Explanation:

You can create an 8 x 8 array using np.array(range(1, 8*8+1)),reshape it to an (8 x 8) array and then, check the position of 50. Be clear that the indexing starts from 0; hence, the 7th row will have the index 6.

Alternatively, you can also use np.unravel_index(49, (8,8)) on the created array.

Similar questions