# Matrix Operations in AutoIt

## Recommended Posts

I'm going to grok matrix operations over the next few months, and I wanted to use AutoIt, because I'm sick of all ML examples I come across being in Python :)
I'll post example scripts here, starting from the most basic operations (addition, subtraction, multiplication etc). This is primarily so that people checking out basic ML applications of AutoIt have some resources to work with. My own use cases are to do with natural language processing and vector embeddings, so I'll eventually throw in domain-specific examples.

I'm going to use the excellent Eigen4AutoIt UDF by @RTFC - - it's a monster of a UDF, and I hope to scratch its surface, example by example...wish me luck

`NOTE: When using the Eigen4AutoIt library, remember to set the value of \$EIGEN_DLLPATH - - read the Eigen4AutoIt QuickStart Manual (page 2) for details.`
##### Share on other sites

EXAMPLE #1 - MATRIX MULTIPLICATION FOR 2 MATRICES

Make sure that your matrices are the right size before multiplying (The number of columns in the first matrix must match the number of rows in the second).

```#include <Eigen4AutoIt.au3>

_Eigen_Startup()
Local \$MatrixA = _Eigen_CreateMatrix(2,4)
Local \$MatrixB = _Eigen_CreateMatrix(4,2)

; Matrix A
_Eigen_WriteMatrixValue(\$MatrixA, 0, 0, 34)
_Eigen_WriteMatrixValue(\$MatrixA, 0, 1, 254)
_Eigen_WriteMatrixValue(\$MatrixA, 0, 2, 9)
_Eigen_WriteMatrixValue(\$MatrixA, 0, 3, 94)

_Eigen_WriteMatrixValue(\$MatrixA, 1, 0, 23)
_Eigen_WriteMatrixValue(\$MatrixA, 1, 1, 98)
_Eigen_WriteMatrixValue(\$MatrixA, 1, 2, 10)
_Eigen_WriteMatrixValue(\$MatrixA, 1, 3, 120)

_MatrixDisplay(\$MatrixA)

; Matrix B
_Eigen_WriteMatrixValue(\$MatrixB, 0, 0, 13)
_Eigen_WriteMatrixValue(\$MatrixB, 0, 1, 45)

_Eigen_WriteMatrixValue(\$MatrixB, 1, 0, 75)
_Eigen_WriteMatrixValue(\$MatrixB, 1, 1, 30)

_Eigen_WriteMatrixValue(\$MatrixB, 2, 0, 239)
_Eigen_WriteMatrixValue(\$MatrixB, 2, 1, 876)

_Eigen_WriteMatrixValue(\$MatrixB, 3, 0, 54)
_Eigen_WriteMatrixValue(\$MatrixB, 3, 1, 32)

_MatrixDisplay(\$MatrixB)

Local \$MatMul = _Eigen_Multiply_AB(\$MatrixA, \$MatrixB, 0)
_MatrixDisplay(\$MatMul)

_Eigen_ReleaseMatrix(\$MatrixA)
_Eigen_ReleaseMatrix(\$MatrixB)

_Eigen_CleanUp()```

##### Share on other sites

EXAMPLE #2 - SETTING ZERO VALUES FOR ALL COLUMNS AND ROWS

```#include <Eigen4AutoIt.au3>

_Eigen_Startup()

Local \$Matrix = _Eigen_CreateMatrix(2,6)

_Eigen_WriteMatrixValue(\$Matrix, 0, 0, 34)
_Eigen_WriteMatrixValue(\$Matrix, 0, 1, 254)
_Eigen_WriteMatrixValue(\$Matrix, 0, 2, 9)
_Eigen_WriteMatrixValue(\$Matrix, 0, 3, 94)
_Eigen_WriteMatrixValue(\$Matrix, 0, 4, 2)
_Eigen_WriteMatrixValue(\$Matrix, 0, 5, 7)
_Eigen_WriteMatrixValue(\$Matrix, 1, 0, 23)
_Eigen_WriteMatrixValue(\$Matrix, 1, 1, 98)
_Eigen_WriteMatrixValue(\$Matrix, 1, 2, 10)
_Eigen_WriteMatrixValue(\$Matrix, 1, 3, 120)
_Eigen_WriteMatrixValue(\$Matrix, 1, 4, 8)
_Eigen_WriteMatrixValue(\$Matrix, 1, 5, 5)

_MatrixDisplay(\$Matrix)
_MatrixDisplay(_Eigen_SetZero(\$Matrix))
_Eigen_ReleaseMatrix(\$Matrix)

_Eigen_CleanUp()```

##### Share on other sites

EXAMPLE #3 - TRANSPOSING A MATRIX

```#include <Eigen4AutoIt.au3>

_Eigen_Startup()

Local \$Matrix = _Eigen_CreateMatrix(12, 15)
_Eigen_SetRandom(\$Matrix)

_MatrixDisplay(\$Matrix)

Local \$TransposedMatrix = _Eigen_Transpose(\$Matrix)
_MatrixDisplay(\$TransposedMatrix)

_Eigen_ReleaseMatrix(\$Matrix)
_Eigen_ReleaseMatrix(\$TransposedMatrix)

_Eigen_CleanUp()```

## Create an account

Register a new account

• ### Similar Content

• #### Eigen4AutoIt - Matrix computing with Eigen 1 2 3 4 5

By RTFC,

• 92 replies
• 36,649 views

By UEZ,

• 0 replies
• 1,347 views
• #### A BitMask-based Sudoku Solver

By RTFC,

• 11 replies
• 4,320 views
• #### Eigen4AutoIt

By RTFC,

• 49,205 views
• #### Artificial Intelligence Neural Networks

By DynamicRookie,

• 10 replies
• 4,037 views
×

• Wiki

• Back

• #### Beta

• Git
• FAQ
×
• Create New...