Re: how to Split sparsearray

• To: mathgroup at smc.vnet.net
• Subject: [mg74125] Re: how to Split sparsearray
• From: Peter Pein <petsie at dordos.net>
• Date: Mon, 12 Mar 2007 04:34:39 -0500 (EST)
• References: <esr1b8\$6nl\$1@smc.vnet.net>

```Arkadiusz.Majka at gmail.com schrieb:
> Hi,
>
> I have very long list of elements >= 0 with more than 90% of zero's
> written in SparseArray structure.
>
> sparseList=SparseArray[list];
>
> I want to split it into sublist of zeros and elements greater than
> zero and obtain again Sparsearray structure. I can do it by
>
> Split[Normal[sparseList],#1=E2=89=A40===#2<=0&];
> SparseArray/@%
>
> Is it better way to do it? Is it possible to do it WITHOUT calling
> Normal (to save time and cache)?
>
> Thx,
>
> Arek
>
>

Hi Arek,

you can use the ArrayRules:

In[1]:= test = SparseArray[Table[(#1*Boole[#1*10 < 1] & )[Random[]], {10^6}]]
Out[1]= SparseArray[<99903>,{1000000}]

In[2]:= First[Timing[
notZero = SparseArray[Last /@ Most[ArrayRules[test]]];
zeroes = SparseArray[{}, {Length[test] - Length[notZero]}];
]]
Out[2]= 0.25*Second

In[3]:= {zeroes, notZero}
Out[3]= {SparseArray[<0>, {900097}], SparseArray[<99903>, {99903}]}

HTH,
Peter

```

• Prev by Date: ComplexityFunction
• Next by Date: Re: Factorizing...
• Previous by thread: how to Split sparsearray
• Next by thread: Kernel needs a lot CPU-Time when idle (WinVista)