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 12, 2018 in Python by bug_seeker
• 15,350 points
67 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 12, 2018 by Priyaj
• 56,520 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,720 points
74 views
0 votes
1 answer
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,720 points
435 views
0 votes
1 answer

How to create and read from a temporary file in Python?

Hi, there is a very simple solution ...READ MORE

answered Jan 29 in Python by Nymeria
• 3,520 points
67 views
0 votes
1 answer

NumPy Array Indexing

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

answered Jul 26 in Python by SDeb
• 13,160 points
23 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
50 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 24, 2018 in Python by Priyaj
• 56,520 points
32 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 in Python by rajesh
• 1,210 points
82 views