How to find index from raw and column in python?

0 votes

I would like to use in np.put() function, but it requires, target indices, interpreted as integers.

[Problem:] I know raw and column, but now I need to find an index. In my case I have matrix 6 by 6 and I would like to find an index of data[3,3].

heatmap = np.zeros((6,6), dtype=int);
index? = someFuction(heatmap[r,c]);

I have tried to use functions like where(), enumerate() and shape(), but it didn't work.

It should be a very basic solution, but I couldn't find it anywhere online.

Sep 24, 2018 in Python by bug_seeker
• 15,510 points
167 views

1 answer to this question.

0 votes

You probably want to use np.ravel_multi_index:

import numpy as np
heatmap = np.zeros((6,6), dtype=int)
index = np.ravel_multi_index([[3], [3]], heatmap.shape)
print(index)
>>> [21]
answered Sep 24, 2018 by Priyaj
• 57,700 points

Related Questions In Python

0 votes
1 answer

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

You probably want to use np.ravel_multi_index: [code] import numpy ...READ MORE

answered Apr 16, 2018 in Python by charlie_brown
• 7,780 points
348 views
0 votes
2 answers
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 in Python by Niroj
• 67,020 points
71 views
0 votes
1 answer

How to handle AssertionError in Python and find out which line or statement it occurred on?

Use the traceback module: import sys import traceback try: ...READ MORE

answered Dec 17, 2018 in Python by charlie_brown
• 7,780 points
2,097 views
0 votes
1 answer

NumPy Array Indexing

If you want to create a subarray ...READ MORE

answered Jul 26, 2019 in Python by SDeb
• 13,250 points
131 views
+1 vote
2 answers

View onto a numpy array?

 just index it as you normally would. ...READ MORE

answered Oct 18, 2018 in Python by roberto
119 views
0 votes
1 answer
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
• 57,700 points
186 views
–1 vote
2 answers

How to find the size of a string in Python?

following way to find length of string  x ...READ MORE

answered Mar 29, 2019 in Python by rajesh
• 1,230 points
319 views