[SciPy-User] element-wise exponentiation

Christopher Mutel cmutel@gmail....
Thu Sep 9 06:28:22 CDT 2010


It is usually easier to mathematical operations on a compressed
matrix, e.g. CSR or CSC. Access the arrays that hold actual data is
much easier (in my opinion).

One simple option would be:
A = A.tocsr()
A.data = A.data**0.2 # This is the array that hold the actual values
in the sparse matrix
A = A.tolil() # If desired

-Chris

On 9 September 2010 13:14, Marcel Blattner <blattnem@gmail.com> wrote:
> Hi
> I have a beginners question. I have to exponentiate each element of a sparse
> lil-matrix.
> I did:
> a,b = A.nonzero()
> for i in range(a.size):
>       A[a[i],b[i]] = A[a[i],b[i]]**0.2
> Is there a way to do something like A**0.2 like in numpy?
> Cheers
>
> _______________________________________________
> SciPy-User mailing list
> SciPy-User@scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
>
>


More information about the SciPy-User mailing list