Skip to content

Commit

Permalink
BUG: Unable to delete row from lil matrix after scalar multiplication (
Browse files Browse the repository at this point in the history
…closes #1427).
  • Loading branch information
stefanv committed Nov 2, 2011
1 parent 84c4247 commit 7cdfb34
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
8 changes: 4 additions & 4 deletions scipy/sparse/lil.py
Expand Up @@ -359,16 +359,16 @@ def _mul_scalar(self, other):
else:
new = self.copy()
# Multiply this scalar by every element.
new.data = np.array([[val*other for val in rowvals] for
rowvals in new.data], dtype=object)
new.data[:] = [[val*other for val in rowvals] for
rowvals in new.data]
return new

def __truediv__(self, other): # self / other
if isscalarlike(other):
new = self.copy()
# Divide every element by this scalar
new.data = np.array([[val/other for val in rowvals] for
rowvals in new.data], dtype=object)
new.data = [[val/other for val in rowvals] for
rowvals in new.data]
return new
else:
return self.tocsr() / other
Expand Down
5 changes: 5 additions & 0 deletions scipy/sparse/tests/test_base.py
Expand Up @@ -1500,6 +1500,11 @@ def test_point_wise_multiply(self):
[0,0,9],
[0,16,0]])

def test_lil_multiply_removal(self):
"""Ticket #1427."""
a = lil_matrix(np.ones((3,3)))
a *= 2.
a[0, :] = 0


class TestCOO(_TestCommon, TestCase):
Expand Down

0 comments on commit 7cdfb34

Please sign in to comment.