Search code examples
javamatrixaveragelinear-algebraojalgo

How to get average of elements along columns or rows in an ojAlgo matrix?


Is there a way to compute the average of the primitive elements along the columns or rows of a matrix, such that we obtain vectors with the average values?

For example, let

A = [[1, 2, 3],[4, 5, 6]]

be a 2x3 matrix. The column-wise average would be retrieved in a 3-element vector, like [2.5, 3.5, 4.5], while the row-wise average would be retrieved in a 2-element vector, like [2, 5].

Numpy and Matlab offer this functionality, and I was wondering if there is such availability in ojAlgo. This, of course, would preclude the use of loops, which is desired in our case.


Solution

  • No, currently you have to do some looping yourself, but please open an issue for this at GitHub.

    https://github.com/optimatika/ojAlgo/issues

    (It will be implemented.)