MathGroup Archive 2005

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

Search the Archive

Re: Manipulating a matrix

  • To: mathgroup at smc.vnet.net
  • Subject: [mg59331] Re: Manipulating a matrix
  • From: "Peltio" <peltio at trilight.zone>
  • Date: Sat, 6 Aug 2005 01:29:22 -0400 (EDT)
  • References: <200508020442.AAA16742@smc.vnet.net> <dcplkm$6od$1@smc.vnet.net>
  • Reply-to: "Peltio" <peltioNOSPAM at despammed.com.invalid>
  • Sender: owner-wri-mathgroup at wolfram.com

"Adel Elsabbagh" wrote

[snip]
>want to drop the i1,i2,...in rows and j1,j2,...jn columns write:
>
>m = m[[Drop[ Range[n],{i1,i2,...,in} ], Drop[ Range[n],{j1,j2,...,jn} ] ]]

Are you sure you didn't mean

    m = m[[
        Delete[ Range[nrows], {{i1}, {i2}, ..., {in}} ],
        Delete[ Range[ncols], {{j1}, {j2}, ..., {jn}} ]
    ]]

instead?

Or has Drop's syntax changed in the latest versions?

cheers,
Peltio
Invalid address in reply-to. Crafty demunging required to mail me.

PS
We could brew a procedure right here, right now:

   matDrop[m_, rowlist_, collist_] := Module[
        {nrows, ncols},
            {nrows, ncols} = Dimensions[m];
            m[[
                Delete[ Range[nrows], List /@ rowlist ],
                Delete[ Range[ncols], List /@ collist ]
            ]]
    ]

e.g.
matDrop[m,{1},{1}] (* drops first row and column *)
matDrop[m,{1,3},{}] (* drops rows 1 and 3 *)
matDrop[m,{},{2,4}] (* drops columns 2 and 4 *)
matDrop[m,{1,3},{2,4}] (* drops rows 1 and 3 and columns 2 and 4 *)


  • Prev by Date: Re: pairs and subsets challenge
  • Next by Date: Re: Manipulating a matrix
  • Previous by thread: Re: Manipulating a matrix
  • Next by thread: Re: Manipulating a matrix