Examples

Summing numbers in a matrix

int[,] data = new int[,] { ... };
int sum = data.AsEnumerable().Sum();

Matrix scalar multiplication

double[,] A = ...;
double c  = ...;

double[,] product = A.Map(e => c * e);

Matrix addition

double[,] A = ..., B = ...;

double[,] sum = A.Combine(B, (x, y) => x + y);

Matrix multiplication

double[,] A = ..., B = ...;

double[,] product = A.CrossJoin(B, (x, y) => x * y, r => r.Sum());

Scaling down images to 50%

int[,] pixels = ...;

int[,] scaledTo50 = pixels.Split(2, 2).Map(e => (int)e.AsEnumerable().Average());

Checking a sudoku solution

int[,] puzzle = ...;

bool isSolution =
	// rows
	puzzle.AsRows()

	// columns
	.Union(puzzle.AsColumns())

	// regions
	.Union(puzzle.Split(3, 3).AsEnumerable().Select(e => e.To1DArray()))

	// check all
	.All(g => Enumerable.Range(1, 9).All(e => g.Contains(e)))
;

Last edited Nov 17, 2012 at 4:17 PM by BlueCode, version 5

Comments

No comments yet.