Skip to content

Added matrix multiplication #471

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
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

HarsheetKakar
Copy link

(Put an X inside the [ ] to denote check mark [X].)

  • If creating a new file :

    • added links to it in the README files ?
    • included tests with it ?
    • added description (overview of algorithm, time and space compleixty, and possible edge case) in docstrings ?
  • if done some changes :

  • other

@HarsheetKakar
Copy link
Author

(Put an X inside the [ ] to denote check mark [X].)

  • If creating a new file :

    • added links to it in the README files ?
    • included tests with it ?
    • added description (overview of algorithm, time and space compleixty, and possible edge case) in docstrings ?
  • if done some changes :

  • other

Copy link
Collaborator

@christianbender christianbender left a comment

Choose a reason for hiding this comment

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

Good Work! I have some suggestions

B = [[5, 8, 1, 2],
[6, 7, 3, 0],
[4, 5, 9, 1]]
import pprint
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please write imports at the begin of the file.

Copy link
Author

Choose a reason for hiding this comment

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

I just wanted to import pprint if the user is running .py file otherwise there is no need to import at all.

[6, 7, 3, 0],
[4, 5, 9, 1]]
import pprint
pprint.pprint(multiply(A,B))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please write the expected output of the test.

result[i][j] += A[i][k] * B[k][j]
return result

if __name__ == "__main__":
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you write a unit test? See directory tests. It exists for every directory in algorithms a py-file with tests.

Copy link
Author

Choose a reason for hiding this comment

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

Yeah I guess that was the major issue, will be working on it, thanks

if it can be multiplied it multiplies them in O(n^3) time
"""

def multiply(A: list,B: list)->list:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please put in a space between ,B . And a space between operators like -> or =

if(colsA != rowsB):
raise Exception("Matrices cannot be multipled")

result=[[0 for i in range(colsB)] for j in range(rowsA)]#create a result matrix
Copy link
Collaborator

Choose a reason for hiding this comment

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

Instead of [0 for i range(colsB)] you can simply write ([0] * colsB)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants