Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

https://gitlab.com/olivierlenoir/MicroPython-Matrix

MicroPython basic matrix operations
https://gitlab.com/olivierlenoir/MicroPython-Matrix

matrix micropython

Last synced: 2 months ago
JSON representation

MicroPython basic matrix operations

Lists

README

        

Author: Olivier Lenoir -
Created: 2021-01-21 22:00:48
License: MIT, Copyright (c) 2021 Olivier Lenoir
Project: Matrix with MicroPython
Description: Basic matrix operation

README
Class Matrix can add, sub, mul matrix.

With Matrix a, b, c, d and e

a = [[1, 2, 3], [4, 5, 6]]
b = [[10, 11], [20, 21], [30, 31]]
c = [[-23, 3, 8], [-13, 17, -21]]
d = [[32, 17], [-3, 11]]
e = [[9, 8, 7], [6, 5, 4]]

a.dim() = (2, 3)
b.dim() = (3, 2)
c.dim() = (2, 3)
d.dim() = (2, 2)
e.dim() = (2, 3)

a + c = [[-22, 5, 11], [-9, 22, -15]]
a - c = [[24, -1, -5], [17, -12, 27]]

a + 2 = [[3, 4, 5], [6, 7, 8]]
2 + a = [[3, 4, 5], [6, 7, 8]]

a - 3 = [[-2, -1, 0], [1, 2, 3]]
3 - a = [[-2, -1, 0], [1, 2, 3]]

a * 2 = [[2, 4, 6], [8, 10, 12]]
2 * a = [[2, 4, 6], [8, 10, 12]]

a * c = [[-23, 6, 24], [-52, 85, -126]]

e *= 3 : [[27, 24, 21], [18, 15, 12]]

a @ b = [[140, 146], [320, 335]]
b @ a = [[54, 75, 96], [104, 145, 186], [154, 215, 276]]

a @ b + d = [[172, 163], [317, 346]]
a @ b + c @ b = [[210, 204], [-100, -102]]

a += c : [[-22, 5, 11], [-9, 22, -15]]
a -= c : [[1, 2, 3], [4, 5, 6]]

a += 2 : [[3, 4, 5], [6, 7, 8]]
a += -2 : [[1, 2, 3], [4, 5, 6]]

a -= 3 : [[-2, -1, 0], [1, 2, 3]]
a -= -3 : [[1, 2, 3], [4, 5, 6]]

a @= b : [[140, 146], [320, 335]]

c @ b + a = [[210, 204], [-100, -102]]
c @ b + a - d = [[178, 187], [-97, -113]]

FORUM
https://forum.micropython.org/viewtopic.php?f=15&t=9613