How can I find out the index of an element from row and column in Python

0 votes
I have the rows and columns of a matrix and need to find the index. In my case I have a 6x6 matrix and would like to
find the index of the data at [3,3]

here's my code

[code]
heatmap = np.zeros((6,6), dtype=int);
index? = someFuction(heatmap[r,c]);
[/code]
Apr 16, 2018 in Python by aryya
• 7,460 points
2,359 views

1 answer to this question.

0 votes
You probably want to use np.ravel_multi_index:

[code]
import numpy as np
heatmap = np.zeros((6,6), dtype=int)
index = np.ravel_multi_index([[3], [3]], heatmap.shape)
print(index)
>>> [21]
[/code]
answered Apr 16, 2018 by charlie_brown
• 7,720 points

Related Questions In Python

0 votes
1 answer

How to find the value of a row in a csv file in python and print column and row of that value ?

Hello @Khanhh , Use panda to find the value of ...READ MORE

answered Oct 15, 2020 in Python by Niroj
• 82,840 points
6,794 views
0 votes
1 answer

How to find index from raw and column in python?

You probably want to use np.ravel_multi_index: import numpy as ...READ MORE

answered Sep 12, 2018 in Python by Priyaj
• 58,020 points
971 views
0 votes
1 answer

How to find index from raw and column in python?

You probably want to use np.ravel_multi_index: import numpy as ...READ MORE

answered Sep 24, 2018 in Python by Priyaj
• 58,020 points
1,300 views
+1 vote
1 answer
0 votes
1 answer

How can I find the square of a number in python?

You can use the exponentiation operator or ...READ MORE

answered May 21, 2019 in Python by Mohammad
• 3,230 points
1,246 views
0 votes
0 answers
+1 vote
4 answers

How do I remove an element from a list by index in Python?

Delete the List and its element: We have ...READ MORE

answered Jun 7, 2020 in Python by sahil
• 500 points
280,832 views
+2 votes
3 answers

How can I play an audio file in the background using Python?

down voteacceptedFor windows: you could use  winsound.SND_ASYNC to play them ...READ MORE

answered Apr 4, 2018 in Python by charlie_brown
• 7,720 points
13,571 views
+2 votes
2 answers

In a list of dictionaries, how can I find the minimum calue in a common dictionary field.

There are several options. Here is a ...READ MORE

answered Apr 10, 2018 in Python by charlie_brown
• 7,720 points
1,426 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP