-
-
Notifications
You must be signed in to change notification settings - Fork 49.7k
added a transpose file #14027
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
Open
apoorvd06
wants to merge
5
commits into
TheAlgorithms:master
Choose a base branch
from
apoorvd06:new-branch
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+38
−0
Open
added a transpose file #14027
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e282f87
added a transpose file
apoorvd06 4d13091
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] fb68c7e
Fix spelling error (codespell)
apoorvd06 4a0da3c
added returning value to the function
apoorvd06 20ffb35
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| """ | ||
| finding tanspose of the given matrix | ||
| The transpose of a matrix is a new matrix formed by | ||
| flipping the original matrix over its main diagonal, | ||
| effectively interchanging its rows and columns | ||
| suppose A=[[1,2,3], | ||
| [4,5,6], | ||
| [7,8,9]] | ||
| is the given matrix then it's transpose will be | ||
| A^t=[[1,4,7], | ||
| [2,5,8], | ||
| [3,6,9]] | ||
| Apporoach: | ||
| 1. Create a empty(null) matrix of the same size of the given matrix | ||
| 2.traverse the given matrix by using nested for loop | ||
| 3.copy the elements in oppposite order of the traversl | ||
| i.e. trans[j][i]=matrix[i][j] | ||
| """ | ||
|
|
||
|
|
||
| def transpose(matrix: list[list[int]]) ->list[list[int]]: | ||
| # create a null matrix of same dimension of given matrix | ||
| trans = [[0] * len(matrix) for _ in range(len(matrix[0]))] | ||
| for i in range(len(matrix)): | ||
| # row wise traversal | ||
| for j in range(len(matrix[0])): | ||
| # column wise traversal | ||
| trans[j][i] = matrix[i][j] | ||
| # copying the elements in null matrix | ||
| return trans | ||
|
|
||
|
|
||
| # checking for main function | ||
| if __name__ == "__main__": | ||
| # matrix(given) | ||
| mat = [[1, 2, 3], [4, 5, 6]] | ||
| # call the function with mat as parameter | ||
| print(transpose(mat)) | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As there is no test file in this pull request nor any test function or class in the file
matrix/transpose_of_matrix.py, please provide doctest for the functiontranspose