-
-
Notifications
You must be signed in to change notification settings - Fork 46.8k
Added OOP approach to matrices #1165
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
Conversation
…responding doctests
…onding doctests) to matrix_class.py A small bug persists that causes the doctest to fail. After a couple Matrix objects are printed, the next one is printed in a different format.
I have now added all methods I intended to, but can add more if people have suggestions. I also formatted with python/black as recommended. One mild bug that persists is the issue of printing out Matrix objects. For some reason, after a couple (I believe it's two, but it might vary) are printed, the next one to be printed is formatted incorrectly. This causes the doctest to fail in one case. I don't believe this is an error with the str method because when playing around in IDLE I found that I can get any Matrix to print correctly, but when I print a few in a row the bug occurs. Please let me know if anyone knows how to fix this, as well as any general feedback. |
…ests in matrix_class.py. Also implemented eq and ne comparison operations
|
…d and fixed bug in cofactors method
|
Try this at the end of the code. Your program will never terminate if given input is larger than 4. if __name__ == "__main__":
pass
# import doctest
# test = doctest.testmod()
import random
size = int(input("Input size: "))
mat = [[random.random() * 100 for j in range(1, size+1)] for i in range(size)]
mat = Matrix(mat)
print(mat.determinant()) I think you need more optimizations. |
And I meant clean string style for Your initial commit shows strings like
and I intended
But I don't think fixing |
@McDic I just wanted to say that I've seen your comments and appreciate the feedback. Sorry if it is taking me a while to make changes but school just started for me and I have been very busy. So this might take me a while to complete, but don't think I have forgotten about it. |
This is in a useful state and passes the tests so let’s land and the improvements requested above can come as pull requests. |
* Added OOP aproach to matrices * created methods for minors, cofactors, and determinants and added corresponding doctests * Added methods for adjugate, inverse, and identity (along with corresponding doctests) to matrix_class.py A small bug persists that causes the doctest to fail. After a couple Matrix objects are printed, the next one is printed in a different format. * formatted matrix_class.py with python/black * implemented negation and exponentiation as well as corresponding doctests in matrix_class.py. Also implemented eq and ne comparison operations * changed __str__ method in matrix_class.py to align with numpy standard and fixed bug in cofactors method * removed property decorators from several methods in matrix_class.py
This is far from done but just a little project I was working on for fun that I thought would be nice to add to this repo eventually. I still need to add determinants, cofactors, etc. but I thought it might be good to post this and see if I got any advice / criticisms of things to think or if you guys thought it looked good to keep going the way it is. I just noticed that you guys are now recommending running Python Black, which I haven't done yet but will get to soon. Anyway, let me know what you think!