Extreme Optimization™: Complexity made simple.

Math and Statistics
Libraries for .NET

  • Home
  • Features
    • Math Library
    • Vector and Matrix Library
    • Statistics Library
    • Performance
    • Usability
  • Documentation
    • Introduction
    • Math Library User's Guide
    • Vector and Matrix Library User's Guide
    • Data Analysis Library User's Guide
    • Statistics Library User's Guide
    • Reference
  • Resources
    • Downloads
    • QuickStart Samples
    • Sample Applications
    • Frequently Asked Questions
    • Technical Support
  • Order
  • Company
    • About us
    • Testimonials
    • Customers
    • Press Releases
    • Careers
    • Partners
    • Contact us
Introduction
Deployment Guide
Nuget packages
Configuration
Using Parallelism
Expand Mathematics Library User's GuideMathematics Library User's Guide
Expand Vector and Matrix Library User's GuideVector and Matrix Library User's Guide
Expand Data Analysis Library User's GuideData Analysis Library User's Guide
Expand Statistics Library User's GuideStatistics Library User's Guide
Expand Data Access Library User's GuideData Access Library User's Guide
Expand ReferenceReference

Skip Navigation LinksHome»Documentation»Data Analysis Library User's Guide»Grouping and Aggregation»Aggregating vectors and matrices

Aggregating vectors and matrices

Extreme Optimization Numerical Libraries for .NET Professional

The same methods that are available for aggregating over the columns of data frames are also available for vectors and matrices.

Aggregating over matrices

For matrices, it is possible to aggregate over both the rows and columns. The AggregateRows method aggregates the rows of a matrix into a single vector or, when multiple aggregators have been supplied, a matrix. The AggregateRowsBy method aggregates groups within each row. In the following example, we create a matrix of random numbers and compute the means of its rows. We then create a moving window of length 5, and construct a matrix that contains the moving average of each row:

C#
VB
C++
F#
Copy
var m1 = Matrix.CreateRandom(10, 100);
var rowMeans = m1.AggregateRows(Aggregators.Mean);
var window = Grouping.Window(m1.ColumnCount, 5);
var rowMAs = m1.AggregateRowsBy(window, Aggregators.Mean);
Dim m1 = Matrix.CreateRandom(10, 100)
Dim rowMeans = m1.AggregateRows(Aggregators.Mean)
Dim window = Grouping.Window(m1.ColumnCount, 5)
Dim rowMAs = m1.AggregateRowsBy(window, Aggregators.Mean)

No code example is currently available or this language may not be supported.

let m1 = Matrix.CreateRandom(10, 100)
let rowMeans = m1.AggregateRows(Aggregators.Mean)
let window = Grouping.Window(m1.ColumnCount, 5)
let rowMAs = m1.AggregateRowsBy<float>(window, Aggregators.Mean)

The AggregateColumns method aggregates the columns of a matrix into a single vector or, when multiple aggregators have been supplied, a matrix. The AggregateColumnsBy method aggregates groups within each column. The same example as above, but aggregating over columns instead of rows, becomes:

C#
VB
C++
F#
Copy
var m2 = Matrix.CreateRandom(100, 10);
var columnMeans = m2.AggregateColumns(Aggregators.Mean);
window = Grouping.Window(m2.RowCount, 5);
var columnMAs = m2.AggregateColumnsBy(window, Aggregators.Mean);
Dim m2 = Matrix.CreateRandom(100, 10)
Dim columnMeans = m2.AggregateColumns(Aggregators.Mean)
window = Grouping.Window(m2.RowCount, 5)
Dim columnMAs = m2.AggregateColumnsBy(window, Aggregators.Mean)

No code example is currently available or this language may not be supported.

let m2 = Matrix.CreateRandom(100, 10)
let columnMeans = m2.AggregateColumns(Aggregators.Mean)
let window = Grouping.Window(m2.RowCount, 5)
let columnMAs = m2.AggregateColumnsBy(window, Aggregators.Mean)

There is one more method for aggregating over columns: AggregateColumnsListwiseU. This method is the same as the regular AggregateColumns. method with the following exception: whenever a row contains a missing value, the entire row is treated as missing. This effectively means that the aggregation is performed after first performing listwise deletion of rows with missing values. In the next example, we first set some missing values and then compute the listwise column means of the matrix:

C#
VB
C++
F#
Copy
var m2 = Matrix.CreateRandom(100, 10);
var columnMeans = m2.AggregateColumns(Aggregators.Mean);
window = Grouping.Window(m2.RowCount, 5);
var columnMAs = m2.AggregateColumnsBy(window, Aggregators.Mean);
Dim m2 = Matrix.CreateRandom(100, 10)
Dim columnMeans = m2.AggregateColumns(Aggregators.Mean)
window = Grouping.Window(m2.RowCount, 5)
Dim columnMAs = m2.AggregateColumnsBy(window, Aggregators.Mean)

No code example is currently available or this language may not be supported.

let m2 = Matrix.CreateRandom(100, 10)
let columnMeans = m2.AggregateColumns(Aggregators.Mean)
let window = Grouping.Window(m2.RowCount, 5)
let columnMAs = m2.AggregateColumnsBy(window, Aggregators.Mean)
Aggregating over vectors

Similarly, vectors have Aggregate and AggregateBy methods that aggregate over the entire vector or each group, respectively. In the next example, we create a vector of random values and compute its kurtosis. We then compute the kurtosis of each chunk of length 10:

C#
VB
C++
F#
Copy
var v = Vector.CreateRandom(100);
var K = v.Aggregate(Aggregators.Kurtosis);
var partition = Grouping.Partition(v.Length, 10);
var Ks = v.AggregateBy(partition, Aggregators.Kurtosis);
Dim v = Vector.CreateRandom(100)
Dim K = v.Aggregate(Aggregators.Kurtosis)
Dim partition = Grouping.Partition(v.Length, 10)
Dim Ks = v.AggregateBy(partition, Aggregators.Kurtosis)

No code example is currently available or this language may not be supported.

let v = Vector.CreateRandom(100)
let K = v.Aggregate(Aggregators.Kurtosis)
let partition = Grouping.Partition(v.Length, 10)
let Ks = v.AggregateBy(partition, Aggregators.Kurtosis)

The AggregateColumns method aggregates the columns of a matrix into a single vector or, when multiple aggregators have been supplied, a matrix. The AggregateColumnsBy method aggregates groups within each column. The same example as above, but aggregating over columns instead of rows, becomes:

C#
VB
C++
F#
Copy
var m2 = Matrix.CreateRandom(100, 10);
var columnMeans = m2.AggregateColumns(Aggregators.Mean);
window = Grouping.Window(m2.RowCount, 5);
var columnMAs = m2.AggregateColumnsBy(window, Aggregators.Mean);
Dim m2 = Matrix.CreateRandom(100, 10)
Dim columnMeans = m2.AggregateColumns(Aggregators.Mean)
window = Grouping.Window(m2.RowCount, 5)
Dim columnMAs = m2.AggregateColumnsBy(window, Aggregators.Mean)

No code example is currently available or this language may not be supported.

let m2 = Matrix.CreateRandom(100, 10)
let columnMeans = m2.AggregateColumns(Aggregators.Mean)
let window = Grouping.Window(m2.RowCount, 5)
let columnMAs = m2.AggregateColumnsBy(window, Aggregators.Mean)

There is one more method for aggregating over columns: AggregateColumnsListwiseU. This method is the same as the regular AggregateColumns. method with the following exception: whenever a row contains a missing value, the entire row is treated as missing. This effectively means that the aggregation is performed after first performing listwise deletion of rows with missing values. In the next example, we first set some missing values and then compute the listwise column means of the matrix:

C#
VB
C++
F#
Copy
var m2 = Matrix.CreateRandom(100, 10);
var columnMeans = m2.AggregateColumns(Aggregators.Mean);
window = Grouping.Window(m2.RowCount, 5);
var columnMAs = m2.AggregateColumnsBy(window, Aggregators.Mean);
Dim m2 = Matrix.CreateRandom(100, 10)
Dim columnMeans = m2.AggregateColumns(Aggregators.Mean)
window = Grouping.Window(m2.RowCount, 5)
Dim columnMAs = m2.AggregateColumnsBy(window, Aggregators.Mean)

No code example is currently available or this language may not be supported.

let m2 = Matrix.CreateRandom(100, 10)
let columnMeans = m2.AggregateColumns(Aggregators.Mean)
let window = Grouping.Window(m2.RowCount, 5)
let columnMAs = m2.AggregateColumnsBy(window, Aggregators.Mean)

Copyright (c) 2004-2023 ExoAnalytics Inc.

Send comments on this topic to support@extremeoptimization.com

Copyright © 2004-2023, Extreme Optimization. All rights reserved.
Extreme Optimization, Complexity made simple, M#, and M Sharp are trademarks of ExoAnalytics Inc.
Microsoft, Visual C#, Visual Basic, Visual Studio, Visual Studio.NET, and the Optimized for Visual Studio logo
are registered trademarks of Microsoft Corporation.