Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
Diagonal matrix function done
Browse files Browse the repository at this point in the history
  • Loading branch information
Tinkidinki authored and SagnikDey92 committed Mar 2, 2020
1 parent 268f41a commit 9bc5ef5
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/sage/matrix/matrix_space.py
Original file line number Diff line number Diff line change
Expand Up @@ -1565,6 +1565,22 @@ def identity_matrix(self):

one = identity_matrix

def diagonal_matrix(diag_elements):
""" Docstring needs to be filled. """

if self.__nrows != self.__ncols:
raise TypeError("Diagonal matrix must be square")
elif self.dims()[0] != len(diag_elements):
raise TypeError("Number of elements in the list does not match number of elements on a diagonal of a matrix in this space")
else:
element_list = [0 for i in range(self.dims()[0]**2)]
index = 0
for i in diag_elements:
element_list[index] = i
index = index + self.dims()[0] + 1

return self.matrix(element_list)

def is_dense(self):
"""
Return whether matrices in ``self`` are dense.
Expand Down

0 comments on commit 9bc5ef5

Please sign in to comment.