MathGroup Archive 2007

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: sparsearray and its nonempty cells

  • To: mathgroup at smc.vnet.net
  • Subject: [mg72648] Re: sparsearray and its nonempty cells
  • From: Arkadiusz.Majka at gmail.com
  • Date: Sat, 13 Jan 2007 05:02:13 -0500 (EST)
  • References: <eo4oa3$mhi$1@smc.vnet.net><eo7njr$20l$1@smc.vnet.net>

DearAll,

Of course I can simply use Sort  but I would prefer to obtain already
sorted list directly from

Mysparse/. SparseArray[_, _, _, x_] :> x[[2, 2]]

or from ArrayRules[...].

BTW Most[First/@ArrayRules[Mysparse]] does not produce sorted list
despite what dh wrote.

In practice I have very long list Mysparse/. SparseArray[_, _, _, x_]
:> x[[2, 2]]
and I want to take the maximum of it. This searching takes some time.
If I would have sorted list (given in advance) I would take the last
element.

Take again:

Out[279]=
SparseArray[i_ /; 2 â?¤ i â?¤ 4 :> A, 6]

In[280]:=
% /. SparseArray[_, _, _, x_] :> x[[2,2]]

{{3}, {2}, {4}}

and:


SparseArray[i_ /; 2 â?¤ i â?¤ 4 :> A, 6]//Trace

{{i_ /; 2 â?¤ i â?¤ 4 :> A, i_ /; 2 â?¤ i â?¤ 4 :> A},
    SparseArray[i_ /; 2 â?¤ i â?¤ 4 :> A, 6], {2 â?¤ 1 â?¤
  4, False}, {2 â?¤ 2 â?¤ 4,
    True}, {2 â?¤ 3 â?¤ 4, True}, {2 â?¤ 4 â?¤ 4, True}, {2 â?¤ 5 â?¤
4, False}, {2 â?¤ 6 â?¤
    4, False}, SparseArray[<\[InvisibleSpace]3\[InvisibleSpace]>, {6}]}

Note, that True is for 2, 3 and 4 - ordered!

Wht do you think?

Arek




dh napisaÅ?(a):
> Hi Arek,
> if you say: Mysparse // FullForm you will see that the array is not
> stored in ascending order as you imply. To get your output sorted,
> simply wrap Sort around it.
> Daniel
>
> Arkadiusz.Majka at gmail.com wrote:
> > Hi,
> >
> > I bulit the following sparse array
> >
> > Mysparse=SparseArray[i_ /; 2 â?¤ i â?¤ 11 :> 0.8, 20]
> >
> > in order to find out all nonempty cells in this array I call (I want to
> > avoid Normal)
> >
> >
> > Mysparse/. SparseArray[_, _, _, x_] :> x[[2, 2]]
> >
> > and I get
> >
> > {{8}, {11}, {3}, {7}, {2}, {6}, {10}, {9}, {5}, {4}}
> >
> > This is of course correct, but why it is not sorted????
> >
> > How can I build Mysparse to get sorted list of nonempty cells?
> > 
> > Arek
> >


  • Prev by Date: Re: Integration using mathematica
  • Next by Date: Re: Re: Limit and Root Objects
  • Previous by thread: Re: sparsearray and its nonempty cells
  • Next by thread: Re: Re: sparsearray and its nonempty cells