ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> scipy-user
scipy-user
[SciPy-user] csc, csr sparse complex matrix problems.
by Mark Starnes other posts by this author
Dec 13 2006 7:09PM messages near this date
You have been unsubscribed from the SciPy-user mailing list | Re: [SciPy-user] csc, csr sparse complex matrix problems.
Hi everyone,

I've been trying to get this simple example to work for a couple of days 
now, to no avail.  I noticed at 
http://projects.scipy.org/scipy/scipy/ticket/329 that there seem to be 
come problems with csc and complex values but I'm hoping they're 
unrelated and someone can help me sort this problem!  I couldn't get the 
csc matrix to work at all here - the csr matrix was having a go and 
getting the right answer but now fails too!  Anyway, here's the code.  
I'm using Python2.4.3 on winxp with Scipy0.5.2, Numpy 1.0.1.

Any help will be appreciated.

Best regards,

Mark Starnes.

***

import numpy as n
import scipy as s
from scipy.linsolve import spsolve
from scipy import linalg as la
from numpy import zeros,complex64

# solve kx=f for x, where
#
#/                    \  /    \    /       #| 1+1i  2+2i  3+3i   | |   2  |   | -5+3i  |
#|                    | |      |   |        |
#| 2     3     4+4i   | | 3+2i | = | 1-6i   |
#|                    | |      |   |        |
#| 4+9i 5+10i  2+11i  | |  -3  |   | -3+25i |
#\                    /  \    /    \       /
#


k0=n.array([[1+1j,2+2j,3+3j],[2,3,4+4j],[4+9j,5+10j,2+11j]])
f0=[-5+3j,1-6j,-3+25j]

# Test numpy routine.

k=n.mat(k0)
f=n.mat(f0).T
fsol=s.dot(la.inv(k),f)
print fsol
print k*fsol
# result should = [2, 3+2j, -3].  Numpy passes.

# Test Scipy sparse routines.
k=s.sparse.csc_matrix((3,3),dtype='F')
k[0,0]=1+1j ; k[0,1]=2+2j  ; k[0,2]=3+3j ;
k[1,0]=2    ; k[1,1]=3     ; k[1,2]=4+4j ;
k[2,0]=4+9j ; k[2,1]=5+10j ; k[2,2]=2+11j;

f=zeros((3),complex64)
f[0]=-5+3j
f[1]=1-6j
f[2]=-3+25j

#fsol2=spsolve(k,f)   # this crashes python with typeD, AND with type F
#print fsol2
#print k.dot(fsol2)

k=s.sparse.csr_matrix((3,3),dtype='F')
k[0,0]=1+1j ; k[0,1]=2+2j  ; k[0,2]=3+3j ;
k[1,0]=2    ; k[1,1]=3     ; k[1,2]=4+4j ;
k[2,0]=4+9j ; k[2,1]=5+10j ; k[2,2]=2+11j;

fsol3=spsolve(k,f)   # this crashes python with typeD, originally ok 
with type F
print fsol3         
print k.dot(fsol3)  

_______________________________________________
SciPy-user mailing list
SciPy-user@[...].org
http://projects.scipy.org/mailman/listinfo/scipy-user
Thread:
Mark Starnes
Robert Cimrman
Mark Starnes
Nils Wagner

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved