Skip to content

Added rank of matrix in linear algebra #8687

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

Merged
merged 21 commits into from
May 31, 2023
Merged
Changes from 3 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
52ec964
Added rank of matrix in linear algebra
rudransh61 Apr 24, 2023
df86e10
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Apr 24, 2023
a1e7bb7
Corrected name of function
rudransh61 Apr 25, 2023
6cca1cd
Corrected Rank_of_Matrix.py
rudransh61 Apr 25, 2023
cb96700
Completed rank_of_matrix.py
rudransh61 Apr 25, 2023
c027189
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Apr 25, 2023
d157ec0
delete to rename Rank_of_Matrix.py
rudransh61 Apr 26, 2023
9451960
created rank_of_matrix
rudransh61 Apr 26, 2023
1d026c9
added more doctests in rank_of_matrix.py
rudransh61 Apr 27, 2023
b37b262
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Apr 27, 2023
c8af526
fixed some issues in rank_of_matrix.py
rudransh61 Apr 27, 2023
1b5a31a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Apr 27, 2023
80de4d3
added moreeee doctestsss in rank_of_mtrix.py and fixed some bugss
rudransh61 Apr 27, 2023
9b3fa92
Merge branch 'TheAlgorithms:master' into master
rudransh61 Apr 28, 2023
afb5191
Update linear_algebra/src/rank_of_matrix.py
rudransh61 Apr 30, 2023
301726a
Update linear_algebra/src/rank_of_matrix.py
rudransh61 Apr 30, 2023
e683139
Update linear_algebra/src/rank_of_matrix.py
rudransh61 Apr 30, 2023
cd8d209
Update rank_of_matrix.py
rudransh61 Apr 30, 2023
0b13df6
Merge branch 'TheAlgorithms:master' into master
rudransh61 May 22, 2023
8d6caaf
Update linear_algebra/src/rank_of_matrix.py
cclauss May 30, 2023
fc66a5b
Merge branch 'TheAlgorithms:master' into master
rudransh61 May 31, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions linear_algebra/src/Rank_of_Matrix.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
"""This is a python program that calculates the rank of a matrix"""
""" BY - RUDRANSH BHARDWAJ"""


def swap_rows(a, row1, row2):

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 linear_algebra/src/Rank_of_Matrix.py, please provide doctest for the function swap_rows

Please provide return type hint for the function: swap_rows. If the function does not return a value, please provide the type hint as: def function() -> None:

Please provide descriptive name for the parameter: a

Please provide type hint for the parameter: a

Please provide type hint for the parameter: row1

Please provide type hint for the parameter: row2

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok i will try
Thank you

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done👌

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bot, so no need to reply...just do as it suggests

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

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 linear_algebra/src/Rank_of_Matrix.py, please provide doctest for the function swap_rows

Please provide return type hint for the function: swap_rows. If the function does not return a value, please provide the type hint as: def function() -> None:

Please provide descriptive name for the parameter: a

Please provide type hint for the parameter: a

Please provide type hint for the parameter: row1

Please provide type hint for the parameter: row2

a[row2], a[row1] = a[row1], a[row2]
return a


def Row_Transformation(a, x, row1, row2):

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 linear_algebra/src/Rank_of_Matrix.py, please provide doctest for the function Row_Transformation

Please provide return type hint for the function: Row_Transformation. If the function does not return a value, please provide the type hint as: def function() -> None:

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: Row_Transformation

Please provide descriptive name for the parameter: a

Please provide type hint for the parameter: a

Please provide descriptive name for the parameter: x

Please provide type hint for the parameter: x

Please provide type hint for the parameter: row1

Please provide type hint for the parameter: row2

for i in range(len(a[row2])):
a[row2][i] += a[row1][i] * x
return a


def MatrixRank(a):

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 linear_algebra/src/Rank_of_Matrix.py, please provide doctest for the function MatrixRank

Please provide return type hint for the function: MatrixRank. If the function does not return a value, please provide the type hint as: def function() -> None:

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: MatrixRank

Please provide descriptive name for the parameter: a

Please provide type hint for the parameter: a

ncol = len(a[0])
nrow = len(a)
rank = min(ncol, nrow)

if nrow > ncol:
b = []
for m in range(ncol):
l = []
for n in range(nrow):
l.append(a[n][m])
b.append(l)
a = b
ncol, nrow = nrow, ncol

for r in range(rank):
if a[r][r] != 0:
for j in range(r + 1, nrow):
a = Row_Transformation(a, -(a[j][r] // a[r][r]), r, j)
else:
count1 = True
for k in range(r + 1, nrow):
if a[k][r] != 0:
a = swapRows(a, r, k)
count1 = False
break

if count1:
for i in range(nrow):
a[i][r], a[i][rank - 1] = a[i][rank - 1], a[i][r]
nrow -= 1

count2 = 0
for i in a:
if i == [0] * ncol:
count2 += 1

return rank - count2