[Numpy-discussion] sparse.hstack with empty sparse matrices

2010-04-12 Thread David Koch
Hello, For scipy.sparse.csc_matrices, is there an equivalent for the following dense array operation? Example: tempA = scipy.empty((10,0)) tempB = scipy.random.random((10,1)) scipy.hstack((tempA, tempB)) i.e - you concatenate an empty n x 0 sparse matrix with a n x 1 sparse matrix to yield a n

[Numpy-discussion] Matlab -> NumPy translation and indexing

2007-03-05 Thread David Koch
Hello, I am trying to translate some Matlab code to NumPy. I started reading the NumPy book and, yeah it's a very long read :-/ One thing I am completely confused about are the concpets of "basic" vs. "advanced" indexing. Are there some good examples out there where for the same piece of code - M

Re: [Numpy-discussion] Matlab -> NumPy translation and indexing

2007-03-05 Thread David Koch
Thank you everybody for your replies. Completely off-topic: I just read your sig Christoper: Christopher Barker, Ph.D. Oceanographer Emergency Response Division NOAA/NOS/OR&R Do you work with tsunami early-warning systems? I once had to give a presentation at Uni about the type of buoy

Re: [Numpy-discussion] Matlab -> NumPy translation and indexing

2007-03-14 Thread David Koch
Hi, so one thing I came across now is the following, very simple: Matlab: A = [] while A = [A some_scalar_value] end In Python, I tried: A = empty((0,0)) while A = concatenate((A, array([someScalarValue])), 1) end which returns an error since the shape of the empty A does not

Re: [Numpy-discussion] Matlab -> NumPy translation and indexing

2007-03-14 Thread David Koch
On 3/14/07, Sven Schreiber <[EMAIL PROTECTED]> wrote: If you want a 1d-array in the end you could try empty(0) to start with, and then do hstack((A, your_scalar)) or something like that. Yeah, that works - odd, I thought concatenate((a,b),0) == hstack((a,b)) Thanks /David ___

Re: [Numpy-discussion] Matlab -> NumPy translation and indexing

2007-03-15 Thread David Koch
On 3/14/07, Gael Varoquaux <[EMAIL PROTECTED]> wrote: I definitely second this comment. Using arrays when you are trying to append a lot of data is using the wrong data format. And the code is so much more readable with lists. Thank you, I will consider it, Next thing, I have A_Idx = arr

Re: [Numpy-discussion] Matlab -> NumPy translation and indexing

2007-03-15 Thread David Koch
On 3/15/07, David Koch <[EMAIL PROTECTED]> wrote: ... NumPy equiv for Matlab B(A_idx, A_Idx) Ok, I did like this: A_Idx = array([1, 0]) B = random.randn(3,3) rowInd = kron(ones((1, len(A_Idx)), int), A_Idx[:, newaxis]) colInd = kron(ones((len(A_Idx), 1), int), A_Idx) B[rowInd,

Re: [Numpy-discussion] Matlab -> NumPy translation and indexing

2007-03-20 Thread David Koch
Hi, naive question - how do I get an overview over everything to do with "sparse functionality" in SciPy 0.5.2 ... I can't find any documentation anywhere. /David ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/ma

Re: [Numpy-discussion] Matlab -> NumPy translation and indexing

2007-03-20 Thread David Koch
I will consider it Sven, I thought it was a good idea to collect everything which had to do with Matlab -> Python in one thread. Anyway, Specifically, I was looking for an equivalent to Matlab's "sprand" which allows one to create sparse normally distributed matrices. The function also accepts

[Numpy-discussion] Adapting algorithm to accept Scipy sparse matrix

2007-03-20 Thread David Koch
Hi, I implemented an algorithm in NumPy which assumes that the input is of type ndarray, so elementwise multiplication is done as dot(x,y), equation solving using linalg.solve etc. I now want to modify the whole thing to accept scipy.sparse matrices (which for instance has linsolve.spsolve instea

Re: [Numpy-discussion] Adapting algorithm to accept Scipy sparse matrix

2007-03-21 Thread David Koch
Ok, I will bump this once ... The "worst" problem I encountered is that sparse matrices do not seem to support the kind of indexing I need. At least I get "NotImplementedError: sequence indexing not yet fully supported" and " supports slices only of a single row" errors all the time. Any advice

Re: [Numpy-discussion] Matlab -> NumPy translation and indexing

2007-03-21 Thread David Koch
Ah! So much ado about nothing. What I was looking for was in fact: B[A_idx][:,A_idx] ... it's even explained in the the NumPy for Matlab Users doc on scipy.org /Thank you ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.sci

Re: [Numpy-discussion] Adapting algorithm to accept Scipy sparse matrix

2007-03-21 Thread David Koch
Alright, may all the trickery rest until that day. One thing I need to do however is patch a column of "ones" onto a sparse matrix of format n * d with n >> d. I tried "concatenate" and it didn't work so I did like this: def spInsCol(X): "insert doc string" n, d = shape(X) X = X.tocsc(

Re: [Numpy-discussion] Adapting algorithm to accept Scipy sparse matrix

2007-03-23 Thread David Koch
Hi, Ok, I got it to work now but - damn, it's ugly. I thought I'd have to watch the differences between ndarray and matrix type but it turns out sparseMatrix is yet again different from matrix in several respects when it comes to certain operations. Is this intended or something that will be mend

Re: [Numpy-discussion] Adapting algorithm to accept Scipy sparse matrix

2007-03-26 Thread David Koch
Hi again, I want to select/access several columns from a sparse csc_matrix. The only way I could think of is the following enormously inefficient algorithm which basically initalizes a new lil_matrix (for assigments) and loops over all the specified columns and does sparse -> dense -> sparse. All

[Numpy-discussion] Tuning sparse stuff in NumPy

2007-03-26 Thread David Koch
Hi, I ran some tests on the very same matrices in Matlab/Numpy and it seems that for sparse matrix multipilcation to be faster than dense multiplication - the degree of sparsity has to be much higher in Numpy than in Matlab. Is there anything I can tune in the underlying routines? I need good per

Re: [Numpy-discussion] Tuning sparse stuff in NumPy

2007-03-26 Thread David Koch
On 3/26/07, Robert Cimrman <[EMAIL PROTECTED]> wrote: Could you be more specific on which type of the sparse matrix storage did you use? Hi Robert, I used csc_matrix. /David ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://pro

Re: [Numpy-discussion] Tuning sparse stuff in NumPy

2007-03-26 Thread David Koch
make the whole operation faster. It's still about 1000 times slower than Matlab but 4 times faster than before. Note, that .transpose already switches the matrix On 3/26/07, Robert Cimrman <[EMAIL PROTECTED]> wrote: David Koch wrote: > On 3/26/07, Robert Cimrman <[EMAIL

Re: [Numpy-discussion] Tuning sparse stuff in NumPy

2007-03-27 Thread David Koch
On 3/27/07, Robert Cimrman <[EMAIL PROTECTED]> wrote: ok. now which version of scipy (scipy.__version__) do you use (you may have posted it, but I missed it)? Not so long ago, there was an effort by Nathan Bell and others reimplementing sparsetools + scipy.sparse to get better usability and per