-
-
Notifications
You must be signed in to change notification settings - Fork 46.6k
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
Changes from 3 commits
52ec964
df86e10
a1e7bb7
6cca1cd
cb96700
c027189
d157ec0
9451960
1d026c9
b37b262
c8af526
1b5a31a
80de4d3
9b3fa92
afb5191
301726a
e683139
cd8d209
0b13df6
8d6caaf
fc66a5b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 Please provide return type hint for the function: Please provide descriptive name for the parameter: Please provide type hint for the parameter: Please provide type hint for the parameter: Please provide type hint for the parameter: |
||
a[row2], a[row1] = a[row1], a[row2] | ||
return a | ||
|
||
|
||
def Row_Transformation(a, x, row1, row2): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 Please provide return type hint for the function: Variable and function names should follow the Please provide descriptive name for the parameter: Please provide type hint for the parameter: Please provide descriptive name for the parameter: Please provide type hint for the parameter: Please provide type hint for the parameter: Please provide type hint for the parameter: |
||
for i in range(len(a[row2])): | ||
a[row2][i] += a[row1][i] * x | ||
return a | ||
|
||
|
||
def MatrixRank(a): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 Please provide return type hint for the function: Variable and function names should follow the Please provide descriptive name for the parameter: Please provide type hint for the parameter: |
||
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 |
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
linear_algebra/src/Rank_of_Matrix.py
, please provide doctest for the functionswap_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
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.
Ok i will try
Thank you
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.
Done👌
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.
This is a bot, so no need to reply...just do as it suggests
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.
ok