Given a `scipy.sparse.coo_matrix` matrix how to determine the index and the maxi...
source link: https://www.codesd.com/item/given-a-scipy-sparse-coo-matrix-matrix-how-to-determine-the-index-and-the-maximum-value-of-each-line.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Given a `scipy.sparse.coo_matrix` matrix how to determine the index and the maximum value of each line?
Given a sparse matrixR
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!
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.
Related Articles
How to get the maximum value for each group in Oracle?
How to use the maximum number for each line in awk?
How to determine the maximum value among the specific fields of an array of json objects?
pandas: How to find the maximum values for each category in a column
How to find the maximum value of each group and display their information when using & ldquo; group by & rdquo;
How to select the maximum value for each identifier in the sql selection statement?
How to find the maximum value of a numpy array, with location restrictions?
How do I determine the maximum value of a pid_t?
R how to find the maximum value by a primary key and remove the duplicates
How to find the minimum value of each column in a matrix 10x10 vba excel
How to get the maximum value of two years in R
How to determine the maximum use of the battery in the on-board system with gcc?
How to find the maximum values of similar groups in an object
How to find the maximum value in a table
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK