Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Matrix inversion #195

Open
railsmk opened this issue Aug 25, 2021 · 3 comments
Open

Matrix inversion #195

railsmk opened this issue Aug 25, 2021 · 3 comments

Comments

@railsmk
Copy link

railsmk commented Aug 25, 2021

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

@kojix2
Copy link
Contributor

kojix2 commented Aug 25, 2021

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
Copy link
Contributor

kojix2 commented Aug 25, 2021

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

@railsmk
Copy link
Author

railsmk commented Aug 26, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants