Menu

mean of columns of a matrix?

Help
Matt Daley
2020-08-12
2020-08-13
  • Matt Daley

    Matt Daley - 2020-08-12

    Hello, bit of a newbie here I'm afraid!

    I have a matrix. I want to calculate the mean of each column and place these values into a vector. Is there a standard, simple way to do this? In fact, is there a way, generally, to run a function column-wise on a matrix? For example using Eigen I can calculate the mean of each column of MatrixXd m using this:

    VectorXd means = m.colwise().mean();

    Also, mean() can be replaced by other functions that operate on a vector and return a single value.

    I'd love there to be something equally simple to use in dlib but I can't find it. I'd love to be able to pass in an arbitrary lambda as well as the reducing function.

     
    • Davis

      Davis - 2020-08-13

      You can call sum_rows(m)/m.nr()

      If you want to run a column wize function on a matrix I think the simplest
      and most reasonable way is to just write a for loop. A function that
      applied a lambda would just be a function with a for loop that called the
      lambda.

      On Wed, Aug 12, 2020 at 7:34 AM Matt Daley mbdaley@users.sourceforge.net
      wrote:

      Hello, bit of a newbie here I'm afraid!

      I have a matrix. I want to calculate the mean of each column and place
      these values into a vector. Is there a standard, simple way to do this?
      In fact, is there a way, generally, to run a function column-wise on a
      matrix? For example using Eigen I can calculate the mean of each column of
      MatrixXd m using this:

      VectorXd means = m.colwise().mean();

      Also, mean() can be replaced by other functions that operate on a vector
      and return a single value.

      I'd love there to be something equally simple to use in dlib but I can't
      find it. I'd love to be able to pass in an arbitrary lambda as well as the
      reducing function.


      mean of columns of a matrix?


      Sent from sourceforge.net because you indicated interest in <
      https://sourceforge.net/p/dclib/discussion/442518/>

      To unsubscribe from further messages, please visit <
      https://sourceforge.net/auth/subscriptions/>

       
  • Matt Daley

    Matt Daley - 2020-08-13

    Thanks for the reply. What you suggest sounds reasonable. I shall try that.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.