# [SciPy-dev] Trouble with optimize.fmin_ncg

Nils Wagner nwagner@iam.uni-stuttgart...
Wed Jul 25 13:58:53 CDT 2007

```On Wed, 25 Jul 2007 11:33:09 -0700
"Nathan Bell" <wnbell@gmail.com> wrote:
> On 7/25/07, Nils Wagner <nwagner@iam.uni-stuttgart.de>
>wrote:
>> Thank you very much! It took me a while to locate
>> the bug. Now it works fine again !
>> BTW, is there a way to support sparse vectors such
>> that the outer product of sparse vectors yields
>> a sparse matrix ?
>
> If the vector is represented as an Nx1 sparse matrix V,
>then the outer
> product is simply V*V.T.  Likewise if V is 1xN then the
>outer product
> is V.T*V.  The existing sparse matrix multiplication
>code should do
> these operations efficiently.
>

Great !
And how can I assign complex entries ?

from scipy import *
from scipy.sparse import *
n = 10
A = sparse.lil_matrix((n,1),complex)
A[4,0] = 2.
A[-1,0] = -4.+1j
print (A*A.T).todense()

Nils

A[-1,0] = -4.+1j
File
"/usr/local/lib64/python2.5/site-packages/scipy/sparse/sparse.py",
line 2370, in __setitem__
x = self.dtype.type(x)
TypeError: can't convert complex to float; use abs(z)

```