Skip to content

Commit

Permalink
ENH: Add getrow and getcol to DOK.
Browse files Browse the repository at this point in the history
  • Loading branch information
cowlicks authored and pv committed Aug 21, 2013
1 parent d301a57 commit 5570f8d
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions scipy/sparse/dok.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,24 @@ def copy(self):
new.update(self)
return new

def getrow(self, i):
"""Returns a copy of row i of the matrix as a (1 x n)
DOK matrix.
"""
out = self.__class__((1, self.shape[1]), dtype=self.dtype)
for j in range(self.shape[1]):
out[0, j] = self[i, j]
return out

def getcol(self, j):
"""Returns a copy of column j of the matrix as a (m x 1)
DOK matrix.
"""
out = self.__class__((self.shape[0], 1), dtype=self.dtype)
for i in range(self.shape[0]):
out[i, 0] = self[i, j]
return out

def take(self, cols_or_rows, columns=1):
# Extract columns or rows as indictated from matrix
# assume cols_or_rows is sorted
Expand Down

0 comments on commit 5570f8d

Please sign in to comment.