Re: question about matrix
- To: mathgroup at smc.vnet.net
- Subject: [mg63847] Re: [mg63832] question about matrix
- From: Sseziwa Mukasa <mukasa at jeol.com>
- Date: Thu, 19 Jan 2006 00:02:43 -0500 (EST)
- References: <200601180739.CAA26286@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
On Jan 18, 2006, at 2:39 AM, Tun Myint Aung wrote: > > Dear Mathgroup, > > I have a matrix and it may have rows and columns which are > zeros. I > can drop the rows and columns manually but it is troublesome. So my > question is that how to drop the rows and columns that are zeros > automatically. Here's one approach In[4]:= testZero[a_]:=Equal@@Append[a,0] dropZeroRows[a_?MatrixQ]:=Select[a,!testZero[#]&] dropZeroColumns[a_?MatrixQ]:=Transpose[Select[Transpose[a],!testZero [#]&]] dropZeroRows[{{1,2,3},{0,0,0},{1,2,3}}] dropZeroColumns[{{1,0,1},{2,0,2},{3,0,3}}] Out[7]= {{1,2,3},{1,2,3}} Out[8]= {{1,1},{2,2},{3,3}}
- References:
- question about matrix
- From: "Tun Myint Aung" <tma@nus.edu.sg>
- question about matrix