Repository: scipy/scipy

Issue:
exponential integral Ei of complex values (Trac #900)
_Original ticket http://projects.scipy.org/scipy/ticket/900 on 2009-03-25 by @lebedov, assigned to @pv._

It would be nice if the following function (or some slight variation thereof) could be included in scipy.special so as to permit the computation of the exponential integral of complex arguments:

```
from numpy import pi,log,asarray,complex,iscomplexobj,real,iterable,asscalar                                     
from scipy.special import exp1                                                                                   

def ei(z):                                                                                                       
    """Compute the exponential integral of a complex value."""                                                   

    zc = asarray(z,complex)                                                                                      
    res = -exp1(-zc)+(log(zc)-log(1.0/zc))/2.0-log(-zc)                                                          
    if not iscomplexobj(z):                                                                                      
        res = real(res)                                                                                          
    if iterable(z):                                                                                              
        return res                                                                                               
    else:                                                                                                        
        return asscalar(res) 
```



Discussion:

Resolving patch:
diff --git a/scipy/sparse/lil.py b/scipy/sparse/lil.py
--- a/scipy/sparse/lil.py
+++ b/scipy/sparse/lil.py
@@ -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


Test patch:
diff --git a/scipy/sparse/tests/test_base.py b/scipy/sparse/tests/test_base.py
--- a/scipy/sparse/tests/test_base.py
+++ b/scipy/sparse/tests/test_base.py
@@ -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):