added support for inverse of 3x3 matrix#7355
Merged
cclauss merged 6 commits intoTheAlgorithms:masterfrom Oct 26, 2022
kituuu:inverse_matrix
Merged
added support for inverse of 3x3 matrix#7355cclauss merged 6 commits intoTheAlgorithms:masterfrom kituuu:inverse_matrix
cclauss merged 6 commits intoTheAlgorithms:masterfrom
kituuu:inverse_matrix
Conversation
cclauss
reviewed
Oct 20, 2022
matrix/inverse_of_matrix.py
Outdated
Comment on lines
+35
to
+63
| ... | ||
| ValueError: This matrix has no inverse. | ||
|
|
||
| More examples: | ||
|
|
||
| >>> inverse_of_matrix([]) | ||
| Traceback (most recent call last): | ||
| ... | ||
| ValueError: Please provide a matrix of size 2x2 or 3x3. | ||
|
|
||
| >>> inverse_of_matrix([[],[]]) | ||
| Traceback (most recent call last): | ||
| ... | ||
| ValueError: Please provide a matrix of size 2x2 or 3x3. | ||
|
|
||
| >>> inverse_of_matrix([[1, 2], [3, 4], [5, 6]]) | ||
| Traceback (most recent call last): | ||
| ... | ||
| ValueError: Please provide a matrix of size 2x2 or 3x3. | ||
|
|
||
| >>> inverse_of_matrix([[1, 2, 1], [0,3, 4]]) | ||
| Traceback (most recent call last): | ||
| ... | ||
| ValueError: Please provide a matrix of size 2x2 or 3x3. | ||
|
|
||
| >>> inverse_of_matrix([[1, 2, 3], [7, 8, 9], [7, 8, 9]]) | ||
| Traceback (most recent call last): | ||
| ... | ||
| ValueError: This matrix has no inverse. |
Member
There was a problem hiding this comment.
We should test that all lines between Traceback and the Error are indented by at least four spaces.
Suggested change
| ... | |
| ValueError: This matrix has no inverse. | |
| More examples: | |
| >>> inverse_of_matrix([]) | |
| Traceback (most recent call last): | |
| ... | |
| ValueError: Please provide a matrix of size 2x2 or 3x3. | |
| >>> inverse_of_matrix([[],[]]) | |
| Traceback (most recent call last): | |
| ... | |
| ValueError: Please provide a matrix of size 2x2 or 3x3. | |
| >>> inverse_of_matrix([[1, 2], [3, 4], [5, 6]]) | |
| Traceback (most recent call last): | |
| ... | |
| ValueError: Please provide a matrix of size 2x2 or 3x3. | |
| >>> inverse_of_matrix([[1, 2, 1], [0,3, 4]]) | |
| Traceback (most recent call last): | |
| ... | |
| ValueError: Please provide a matrix of size 2x2 or 3x3. | |
| >>> inverse_of_matrix([[1, 2, 3], [7, 8, 9], [7, 8, 9]]) | |
| Traceback (most recent call last): | |
| ... | |
| ValueError: This matrix has no inverse. | |
| ... | |
| ValueError: This matrix has no inverse. | |
| >>> inverse_of_matrix([]) | |
| Traceback (most recent call last): | |
| ... | |
| ValueError: Please provide a matrix of size 2x2 or 3x3. | |
| >>> inverse_of_matrix([[],[]]) | |
| Traceback (most recent call last): | |
| ... | |
| ValueError: Please provide a matrix of size 2x2 or 3x3. | |
| >>> inverse_of_matrix([[1, 2], [3, 4], [5, 6]]) | |
| Traceback (most recent call last): | |
| ... | |
| ValueError: Please provide a matrix of size 2x2 or 3x3. | |
| >>> inverse_of_matrix([[1, 2, 1], [0,3, 4]]) | |
| Traceback (most recent call last): | |
| ... | |
| ValueError: Please provide a matrix of size 2x2 or 3x3. | |
| >>> inverse_of_matrix([[1, 2, 3], [7, 8, 9], [7, 8, 9]]) | |
| Traceback (most recent call last): | |
| ... | |
| ValueError: This matrix has no inverse. |
cclauss
reviewed
Oct 20, 2022
matrix/inverse_of_matrix.py
Outdated
Comment on lines
+144
to
+151
| adjoint_matrix = [ | ||
| [d(0.0), d(0.0), d(0.0)], | ||
| [d(0.0), d(0.0), d(0.0)], | ||
| [d(0.0), d(0.0), d(0.0)], | ||
| ] | ||
| for i in range(3): | ||
| for j in range(3): | ||
| adjoint_matrix[i][j] = cofactor_matrix[j][i] |
Member
There was a problem hiding this comment.
Suggested change
| adjoint_matrix = [ | |
| [d(0.0), d(0.0), d(0.0)], | |
| [d(0.0), d(0.0), d(0.0)], | |
| [d(0.0), d(0.0), d(0.0)], | |
| ] | |
| for i in range(3): | |
| for j in range(3): | |
| adjoint_matrix[i][j] = cofactor_matrix[j][i] | |
| adjoint_matrix = zip(*cofactor_matrix) |
https://www.geeksforgeeks.org/transpose-matrix-single-line-python
cclauss
reviewed
Oct 20, 2022
matrix/inverse_of_matrix.py
Outdated
| and len(matrix[2]) == 3 | ||
| ): | ||
| # Calculate the determinant of the matrix using Sarrus rule | ||
| determinant = ( |
Member
There was a problem hiding this comment.
Suggested change
| determinant = ( | |
| determinant = float( | |
cclauss
reviewed
Oct 20, 2022
Contributor
Author
|
@cclauss Sir, the zip() method involves a list of tuples. And in my code, every matrix was a list of lists. So I used NumPy.array instead of zip. Also, I don't know what error doctest is giving, can u help me with that? |
13 tasks
Contributor
Author
|
@poyea @cclauss @dhruvmanila Sir, please review this also. And suggest changes if required. 🥲 |
chriso345
reviewed
Oct 26, 2022
CaedenPH
reviewed
Oct 26, 2022
Co-authored-by: Caeden Perelli-Harris <caedenperelliharris@gmail.com> Co-authored-by: Chris O <46587501+ChrisO345@users.noreply.github.com>
cclauss
approved these changes
Oct 26, 2022
Member
cclauss
left a comment
There was a problem hiding this comment.
I applied all code review suggestions.
Thanks for your persistence!!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Describe your change:
Checklist:
Fixes: #{$ISSUE_NO}.