[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Applying function to vector by index

From: Paul Kienzle
Subject: Re: Applying function to vector by index
Date: Thu, 12 Dec 2002 12:31:15 -0500
User-agent: Mutt/

On Thu, Dec 12, 2002 at 05:58:32PM +0100, Schloegl Alois wrote:
> I'd call it flexibility: 
> sparse(a).^(b+i*c) evaluates only the non-zero elements of a. 
> The alternative is always possible with full(a).^(b+i*c)

Even if you treat zeros values correctly you can get flexibility
as follows:

        a = sparse(i,j,f(v),m,n);

Admittedly, this is not as convenient as a = f(sparse(v)) operating
only on the defined values of the sparse matrix.  However, I notice
that matlab returns [-1 1;1 -1] from cos(sparse(pi*eye(2))), so you
will sacrifice compatibility for this convenience.

Personally I would rather not have functions spontaneously converting
sparse matrices to full since really small sparse matrices can form
really big full matrices, but I also would not want to introduce
needless incompatibilities.

BTW, I notice that
returns the following:
        Compressed Column Sparse (rows=1, cols=1, nnz=1)
          (1 , 1) -> 0
        [i,j,v] = spfind(sparse(1,1,0))
        i = 1
        j = 1
        v = 0

I haven't decided if this is a bug or a feature.  I don't know if
this is a compatibility issue.

Paul Kienzle

Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:
How to fund new projects:
Subscription information:

reply via email to

[Prev in Thread] Current Thread [Next in Thread]