MathGroup Archive 2006

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

Search the Archive

Re: how to sort integers and sparsearrays ?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg71997] Re: how to sort integers and sparsearrays ?
  • From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
  • Date: Thu, 7 Dec 2006 06:26:13 -0500 (EST)
  • Organization: The Open University, Milton Keynes, UK
  • References: <el681s$2kb$1@smc.vnet.net>

Arkadiusz.Majka at gmail.com wrote:
> Hi,
> 
> I have a list of a form
> 
> list = {k, {SparseArray[],SparseArray[], {A,SparseArray[]}}}
> 
> A is integer, k is list
> 
> What to do to convert it to
> 
> {{k,A},{SparseArray[],SparseArray[],SparseArray[]}}
> 
> The length of list is unknown. We don't know where A appears. We only
> know that it is integer and forms a list {A, SparseArray[]}.
> 
> I can't just use
> 
> list/.{a___,{b_,c_,{d_,e_}}}
> 
> because this pattern will not suit nither to e.g
> 
> list2=  {{0,3}},
> {{A,SparseArray[]},SparseArray[],SparseArray[],SparseArray[],SparseArray[]}
> 
> 
> nor
> 
> list3=  {{0,3}},
> {SparseArray[],SparseArray[],SparseArray[],SparseArray[],SparseArray[]}
> 
> 
> where there is no A at all.
> 
> Help,
> 
> Arek
> 

Do you mean something along the lines

list2 = {{0, 3}, {{42, mySparseArray[]},
  mySparseArray[], mySparseArray[], mySparseArray[],
  mySparseArray[]}}

--> {{0, 3}, {{42, mySparseArray[]}, mySparseArray[], mySparseArray[], 
mySparseArray[], mySparseArray[]}}

list2 /. {k_List, {a___mySparseArray,
  {n_Integer, s_mySparseArray},
  b___mySparseArray}} -> {{k, n}, {a, s, b}}

--> {{{0, 3}, 42}, {mySparseArray[], mySparseArray[], mySparseArray[], 
mySparseArray[], mySparseArray[]}}

Regards,
Jean-Marc


  • Prev by Date: Re: System of Linear Equations
  • Next by Date: Re: How can I get this spiked Integral evaluated???
  • Previous by thread: how to sort integers and sparsearrays ?
  • Next by thread: System of Linear Equations