Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #8418

Re: Simply but handy question

From Barrie Stokes <Barrie.Stokes@newcastle.edu.au>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: Simply but handy question
Date 2012-02-09 10:41 +0000
Organization Steven M. Christensen and Associates, Inc and MathTensor, Inc.
Message-ID <jh07tk$i07$1@smc.vnet.net> (permalink)
References <201202081029.FAA06451@smc.vnet.net>

Show all headers | View raw


Hi Paul

How about:

y = {{a, b}, {0, c}};

ClearAll[ somethingOrZero]  
somethingOrZero[x_] := If[ SameQ[ x, 0 ], 0, 1 ]

Map[ somethingOrZero, y, {2} ].

Check the online Help for what the parameters of Map are, and what SameQ means.

Barrie

>>> On 08/02/2012 at 9:29 pm, in message <201202081029.FAA06451@smc.vnet.net>,
jediwhelan <jediwhelan@googlemail.com> wrote:
> Dear group members,
> 
> I am new to mathematica (well, I'm not actually but I haven't used it
> in 5 years +).
> 
> Is there an easy way to return a matrix X of 1's and 0's to test
> whether the entries in Y
> are different from zero.
> 
> i.e.,
> 
> if Y = {{a,b},{0,c}}
> 
> Then X would return
> 
> X = {{1,1},{0,1}}
> 
> This would be handy for very large or complicated matrices where one
> would like to know if specific entries are zero?
> 
> Many thanks,
> Paul

Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread


Thread

Re: Simply but handy question Barrie Stokes <Barrie.Stokes@newcastle.edu.au> - 2012-02-09 10:41 +0000

csiph-web