Index of max coefficient (column wise) in Eigen

zmb

In Eigen, I can do a row-wise or column-wise "partial reduction" to get the maximum coefficients.

For example, this program:

#include <iostream>
#include <Eigen/Dense>

int main()
{
  Eigen::MatrixXf mat(2,4);
  mat << 1, 2, 6, 9,
         3, 1, 7, 2;

  std::cout << "Column's maximum: " << std::endl
   << mat.colwise().maxCoeff() << std::endl;
}

Outputs:

Column's maximum:
3 2 7 9

Instead of creating a row vector with the maximum coefficient in each column, I would like to construct a row vector with the index of the maximum coefficient of each column.

In other words, I would like to modify the program so that the output becomes:

Column's maximum:
1, 0, 1, 0

I know I can get the index one column at a time doing something like this:

Eigen::MatrixXf::Index max_index;
mat.col(i).maxCoeff(&max_index);

but I was hoping there was a better way that could do this all in one step instead of manually looping through each column. Is this possible? (I'm using Eigen v3.2.7)

zmb

I found a post on Eigen's user forums from 2012 that suggests this is not possible, and that looping over the rows/columns is indeed the best way.

There is no shorter way yet. Regarding vectorization, vec.maxCoeff() is vectorized (standard reduction), but not the version returning the index: vec.maxCoeff(int&). It's not impossible but I'd not expect significant gain if any.

I briefly grepped through some of the 3.2.7 code base, and it doesn't appear that anything has changed since the post.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

Python Pandas add column for row-wise max value of selected columns

From Dev

Eigen3: coefficient-wise multiplication in place

From Dev

Find every index of max value in a column in two-dimensional list

From Dev

Coefficient-wise custom functions in Eigen

From Dev

Getting the location of the maximum coefficient of an Eigen C++ library Vector

From Dev

New column with column name from max column by index pandas

From Dev

Set coefficient/element of Eigen::Matrix3d in Cython

From Dev

Eigen: how to remove an initialised coefficient from a sparse Matrix

From Dev

Column wise subtraction in numpy

From Dev

Eigen matrix library coefficient-wise modulo operation

From Dev

Finding row index of max column values in a numpy matrix

From Dev

Column index with row-wise maximum value

From Dev

Element-wise max and positive part in Eigen

From Dev

computing lpNorm column wise in Eigen

From Dev

How to group list with index wise?

From Dev

How to make a new column based on difference of max values by index?

From Dev

Fast way to find index of max/min element in Nth column of matrix

From Dev

Getting the location of the maximum coefficient of an Eigen C++ library Vector

From Dev

Get horizontal wise max value

From Dev

Numpy column wise multiplication

From Dev

Large block coefficient-wise multiplication fails in Eigen library C++

From Dev

Eigen Increment Column by One

From Dev

get max value of multiplication of column combinations and their respective index in python

From Dev

Drop duplicates by index, keeping max for each column across duplicates

From Dev

Pandas: Find index of max string value in a column

From Dev

finding occurences of Dataframe column of max value in multi-index case

From Dev

SELECT Max index for multiple column values in the same table?

From Dev

Column wise operation in Spark

From Dev

How to do element-wise comparison with Eigen?

Related Related

  1. 1

    Python Pandas add column for row-wise max value of selected columns

  2. 2

    Eigen3: coefficient-wise multiplication in place

  3. 3

    Find every index of max value in a column in two-dimensional list

  4. 4

    Coefficient-wise custom functions in Eigen

  5. 5

    Getting the location of the maximum coefficient of an Eigen C++ library Vector

  6. 6

    New column with column name from max column by index pandas

  7. 7

    Set coefficient/element of Eigen::Matrix3d in Cython

  8. 8

    Eigen: how to remove an initialised coefficient from a sparse Matrix

  9. 9

    Column wise subtraction in numpy

  10. 10

    Eigen matrix library coefficient-wise modulo operation

  11. 11

    Finding row index of max column values in a numpy matrix

  12. 12

    Column index with row-wise maximum value

  13. 13

    Element-wise max and positive part in Eigen

  14. 14

    computing lpNorm column wise in Eigen

  15. 15

    How to group list with index wise?

  16. 16

    How to make a new column based on difference of max values by index?

  17. 17

    Fast way to find index of max/min element in Nth column of matrix

  18. 18

    Getting the location of the maximum coefficient of an Eigen C++ library Vector

  19. 19

    Get horizontal wise max value

  20. 20

    Numpy column wise multiplication

  21. 21

    Large block coefficient-wise multiplication fails in Eigen library C++

  22. 22

    Eigen Increment Column by One

  23. 23

    get max value of multiplication of column combinations and their respective index in python

  24. 24

    Drop duplicates by index, keeping max for each column across duplicates

  25. 25

    Pandas: Find index of max string value in a column

  26. 26

    finding occurences of Dataframe column of max value in multi-index case

  27. 27

    SELECT Max index for multiple column values in the same table?

  28. 28

    Column wise operation in Spark

  29. 29

    How to do element-wise comparison with Eigen?

HotTag

Archive