Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Associative Matrices?

I'm working on a project where I need to store a matrix of numbers indexed by two string keys. The matrix is not jagged, i.e. if a column key exists for any row then it should exist for all rows. Similarly, if a row key exists for any column then it should exist for all columns.

The obvious way to express this is with an associative array of associative arrays, but this is both awkward and inefficient, and it doesn't enforce the non-jaggedness property. Do any popular programming languages provide an associative matrix either built into the language or as part of their standard libraries? If so, how do they work, both at the API and implementation level? I'm using Python and D for this project, but examples in other languages would still be useful because I would be able to look at the API and figure out the best way to implement something similar in Python or D.

like image 256
dsimcha Avatar asked Feb 11 '10 19:02

dsimcha


People also ask

What is an associative matrix?

Matrix multiplication is associativeIf A is an m×p matrix, B is a p×q matrix, and C is a q×n matrix, then A(BC)=(AB)C.

What is commutative and associative matrix?

We will be discussing the below-mentioned properties: Commutative property of addition i.e, A + B = B+ A. Associative Property of addition i.e, A+ (B + C) = (A + B) + C. Additive identity property. For any matrix A, there is a unique matrix O such that, A+O = A.

What does associative mean in linear algebra?

In mathematics, an associative algebra A is an algebraic structure with compatible operations of addition, multiplication (assumed to be associative), and a scalar multiplication by elements in some field K.

Is matrix difference associative?

So, Matrix subtraction is not associative.


1 Answers

Why not just use a standard matrix, but then have two dictionaries - one that converts the row keys to row indices and one that converts the columns keys to columns indices. You could make your own structure that would work this way fairly easily I think. You just make a class that contains the matrix and the two dictionaries and go from there.

like image 167
Justin Peel Avatar answered Oct 13 '22 00:10

Justin Peel