Given a sparse matrix`R`

of type `scipy.sparse.coo_matrix`

of shape `1.000.000 x 70.000`

I figured out that

```
row_maximum = max(R.getrow(i).data)
```

will give me the maximum value of the i-th row.

**What I need now is the index corresponding to the value row_maximum.**

Any ideas how to achieve that?

Thanks for any advice in advance!

use `numpy.argmax`

(or `scipy.argmax`

which is the same thing)

```
index_of_maximum = scipy.argmax(R.getrow(i).data)
```

`getrow(i)`

returns a 1 x n CSR matrix, which has an `indices`

attribute that gives the row indices of the corresponding values in the `data`

attribute. (We know the shape is 1 x n, so we don't have to deal with the `indptr`

attribute.) So this will work:

```
row = R.getrow(i)
max_index = row.indices[row.data.argmax()] if row.nnz else 0
```

We have to deal with the case where `row.nnz`

is 0 separately, because `row.data.argmax()`

will raise an exception if `row.data`

is an empty array.

Similar Questions

In google spread sheet, Given the following: John 5 Peter 0 Brad 3 Smith 1 Grade1 1 Grade2 2 Grade3 3 Grade4 4 Pass 5 Fail 0 I want to do the following, when I write in the same row say (John Grad1 P

Give a list of 2d points and a maximum distance d, what is a better than O(n^2) way of finding which points are located within d from each point. I don't need a solution just some starting ideas.

Say we have the following matrix 1 3 6 5 4 7 5 3 9 What I'm trying to do is for each row, I assign it the maximum value of the column. So, for instance, I'm expecting the following output: x(1) = 6 x

I've created this matrix: > atr <- matrix(rnorm(18,50,3), nrow=9, ncol=2) > atr [,1] [,2] [1,] 49.1 46.3 [2,] 49.9 49.2 [3,] 52.3 51.6 [4,] 49.3 46.1 [5,] 54.3 51.8 [6,] 46.7 47.2 [7,] 46.6 5

in Chrome when i set z-index to 2147483647 it changes to 1e+06.. what is the maximum possible value for chrome?

I wish to find the maximum element-value of a matrix and it's location (in row and column id in the matrix). I am using the following function to return the row and column of the matrix. This seems

If we have a matrix for 6 rows and 10 columns we have to determine the k value.If we assume default k value is 5 and if we have less columns than 5 with same number of rows 6 can we assume that number

I have a matrix Inter[i,j] whose each element has a set of rows with 3 columns each. for eg. Inter[15,40]= {{0,0,0},{1,1,3}}, Inter[32,64]={{0,0,0},{1,1,3},{2,2,3}} and so on Now i want a matrix MaxGG

i am developing a android database application in which i use a query to find the maximum of row id in the table which is primary key and not auto incremented i referred this link http://www.sqlite.or

I have a DBGrid that shows a filtered view of a dBASE table. DBGrid has a property called RowCount but is marked private. How do I determine the row count? All I really need to know, is whether the co

I get the five double data type values from five different function.Without adding those value into array is there any efficient java code for get the maximum value from that five value set. double d1

Given n arrays of integers, is there a good algorithm with which to determine whether there is a path across those arrays such that the minimum (Euclidean) distance of each step along that path fall

I want to determine the maximum size of the stack programmatically from within Java (the size set by -Xss). How do I do this? Alternatively, as my Java module also uses a native code module, I would b

This question already has an answer here: How to divide each row of a matrix by elements of a vector in R 2 answers I have a matrix with 5 columns and 4 rows. I also have a vector with 3 column

I'm adding rows dinamically in my WebPage and at one moment I want to get the value of each cell in a row. This is the declaration of my row: <tr class=template-upload fade> <td class=nam

Given the letter of a drive, how can I determine what type of drive it is? I.e. whether E:\ is a usb drive, a network drive or a local hard drive.

$VAR1 = [ '830974', '722065', '722046', '716963' ]; How can I calculate the array index for the value 722065?

There is a matrix with m rows and n columns. The task is to find the maximum sum choosing a single element from each row and column. I came up with a solution, which finds the maximum from the whole m

My main query was solved at the following post TSQL - Get the difference between each row value I have one problem of summing the reading values between each row. id device_id time reading shift_id 15

Given the matrix X1 X2 X3 X4 X5 [1,] 1 2 3 2 1 [2,] 2 3 4 4 3 [3,] 3 4 4 6 2 [4,] 4 5 5 5 4 [5,] 2 3 3 3 6 [6,] 5 6 2 8 4 I want to create a distance matrix containing the absolute mean difference b

I want to subset a dataframe (df), in order to contain only the maximum value of each row for columns 1 to 10 and the name of the column. example dataframe: 0 1 2 3 4 0.01 0.12 0.41 0.11 0.11 0.13 0.

Suppose I have a list or data frame in R, and I would like to get the row index, how do I do that? That is, I would like to know how many rows a certain matrix consists of.

I'm sure this has a simple answer, having trouble finding it. So I have matrix g: > g[1:5,1:5] rs7510853 rs10154488 rs12159982 rs2844887 rs2844888 NA06985 CC CC CC CC CC NA06991 CC CC

A=[ 2 4 8 20 0 0; 1 3 6 18 22 0; 0 3 5 8 18 20] and then from the above matrix, I want to account average of max value of every rows. so I wish the result : result=average(20+22+20)=20,67 thankf for

I have a matrix where I want to replace maximum value of each column by -1. How can I do it in R? I tried, set.seed(14) mat<- matrix(sample(10,20,replace=TRUE),nr=5) apply(mat,2,which.max) [1] 3 2

i have a m-rows n-columns matrix in matlab, say M. I have a n-element row vector, i.e. an 1-row n-column matrix, say X. I know X is a row somewhere in M. How can I find the index of M?

I have the following matrix c = [1 2 NaN;2 NaN 1;4 1 NaN;3 NaN NaN] and another matrix A = [ 16 2 3 13; 5 11 10 8; 9 7 6 12; 4 14 15 1 ]. We initialize matrix B=nan(size(A)). I want to use each row of

Suppose I have a function like map zipWith, how can I determine its type? Given that the type of zipWith is (a -> b -> c) -> [a] -> [b] -> [c] and that of map is (a -> b) -> [a] -

I want get the empty data column count in given row by the id. EX: In my table have 15 column. I want to get empty data column count when I pass the value id of the row. Is there any my sql function o

I'm trying to find the maximum value of a certain column in a matrix. I want to find both the maximum value and the index of the row in which it is. How can I do this?

I want to get questions one by one by clicking on button from access database table. Each question is one single row, want to get every next question by clicking on next button from every next row.

I have a requirement to determine the maximum Id int value for a set of tables in my database. The column is always 'Id' and is the primary key. Is there a simple way I can make this determination wit

I could of course use a loop for this, but given my large data matrix this will most likely take forever. I have a data matrix with the dimensions 5000x250. The 5000 values for each subject lie around

A Toeplitz matrix is a matrix in which each descending diagonal from left to right is constant. Given a binary matrix M, is there an efficient algorithm to determine if there is a permutation of the

After running correlations I need to ID the row of the maximum value in each column. I am using which.max but I can not get the row name. Instead I get an index number which is worthless. Each row has

Using the matrix created below: matrix = [] for i in range(0, N): row = [] for j in range(0, M): row.append(i *j) matrix.append(row) I need get all row combinations from this matrix. For example: [ma

I have a table with multiple date columns per employee: Emp 1, Date1, Date2, Date3 Emp 2, Date1, Date2, Date3 etc. I would like to write a single query that returns to me the maximum date of the thr

Given a 2x3 matrix x and a 4x2 matrix y, I'd like to use each row of y to index into x. If the value in x is not equal to -1 I'd like to remove that row from y. Here's an example that does what I'd li

I have a matrix like so: Only in reality it is hundreds or thousands of values. What I need to do is return the minimum value for each row, along with the row/col name. So for row 1 in the example,

can anyone suggest an algorithm for generating a row sorted, column sorted 2-D matrix given a list of integers ? What I mean is that all rows and all columns should be sorted, preferably in asc/desc o

I have a PDF document with a number of text fields, several of which have a maximum length - namely, a maximum number of allowable characters. Is there a way using iTextSharp to determine this setting

I'm looking a way to determine size in bytes of a value type (TypeReference) in Mono.Cecil. I need it to optimize Nullable equality compare code generation. If value type size > 4, compare HasValu

I have a ListView and each row contains button. I don't want to assign to each button its own listener object, cause it will create a lot of objects. But the question is how to determine row number or

I'm working on a T4 template to automatically generate a C# class definition from an XML file. For each element in the XML document I'd like to determine the type of the content in that element. Is th

How to sort a list and get the initial index of a value in matlab. e.g orignal A=[40;30;20;50;60] sorted A=[20;30;40;50;60] indices of sorted A in orignal A =[3;2;1;4;5]

I have use the templete field delete button in gridview, so when I click on any delete button in the gridview to delete a row at that time it will give the deleting row index with that selected row's

What is the maximum recommended size of a value type? I think I read that Microsoft suggests that they are not being larger than 16 bytes, but I can't find the reference.

I have an XML Schema that contains the following type element: <xs:simpleType name=value> <xs:union memberTypes=xs:boolean xs:int xs:double xs:string/> </xs:simpleType> A sample

def findMaxDiff(l): 'list(list(int)), returns index of the row with the maximum difference between elements and the value of the difference in that row' return (max(max(a) - min(a) for a in l), l.inde

I am using Postgres 9.3. I just added a trigger to a table. It is an after insert trigger which is executed for each row after each statement. I coded the trigger function assuming the index of the sa