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 ariaholic
• 7,320 points
50 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
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,710 points

Related Questions In Python

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
• 56,140 points
51 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
• 56,140 points
23 views
0 votes
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 20 in Python by Mohammad
• 1,400 points
14 views
0 votes
0 answers
0 votes
1 answer

How can I compare the content of two files in Python?

Assuming that your file unique.txt just contains ...READ MORE

answered Apr 16, 2018 in Python by charlie_brown
• 7,710 points
41 views
0 votes
1 answer

How can I convert a list of dictionaries from a CSV into a JSON object in Python?

You could try using the AST module. ...READ MORE

answered Apr 17, 2018 in Python by anonymous
472 views
0 votes
1 answer

How can I get the count of a list in Python?

len() >>> mylist=[] >>> print len(mylist) 0 READ MORE

answered Dec 12, 2018 in Python by charlie_brown
• 7,710 points
42 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 3, 2018 in Python by charlie_brown
• 7,710 points
1,053 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,710 points
31 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.