numo-narray icon indicating copy to clipboard operation
numo-narray copied to clipboard

Matrix inversion

Open railsmk opened this issue 2 years ago • 3 comments

Hello, Does this library support matrix inversion? The old version of NArray does but I can't find it here. I searched the Doc and 100 narray exercises but sadly I didn't find anything. Can I maybe find it under a different name?

Thanks

railsmk avatar Aug 25 '21 09:08 railsmk

I think one way is to use Numo::Linalg.

require 'numo/linalg'
# require 'numo/linalg/autoloader'

a = Numo::DFloat[[1, 2], [3, 4]]
ainv = Numo::Linalg.inv(a)

p a.dot(ainv)
p Numo::Linalg.dot(a, ainv)

a = Numo::DFloat.cast([[[1, 2], [3, 4]], [[1, 3], [3, 5]]])
p Numo::Linalg.inv(a)

Same result as numpy.linalg.inv.

kojix2 avatar Aug 25 '21 13:08 kojix2

@masa16 Is there any way to perform inv without using Numo::Linalg?

kojix2 avatar Aug 25 '21 23:08 kojix2

Good to know, I was thinking about using Numo::Linalg library anyways. I modified basic dot method for my own use, so now it multiplies matrices in Galois/Finite fields but realized too late that library doesn't include inv method. Thanks for help, of course if there is a way to do it without using Numo::Linalg I would also appreciate the answer. Take care.

railsmk avatar Aug 26 '21 08:08 railsmk