MathGroup Archive 2012

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

Search the Archive

Re: Simply but handy question

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.


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,


Hi, Paul,

Try this:

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

matrix2 = {{a, b, 0}, {c, 0, 15}, {0, 2, d}};

g[a_] := If[a =!= 0, 1, 0];

Map[g, matrix1, {2}] // MatrixForm

Map[g, matrix2, {2}] // MatrixForm

Have fun, Alexei

Alexei BOULBITCH, Dr., habil.


ZAE Weiergewan,

11, rue Edmond Reuter,

L-5326 Contern, LUXEMBOURG

Office phone :  +352-2454-2566

Office fax:       +352-2454-3566

mobile phone:  +49 151 52 40 66 44

e-mail: alexei.boulbitch at<mailto:alexei.boulbitch at>

  • Prev by Date: plotting
  • Next by Date: Re: Simply but handy question
  • Previous by thread: Re: Simply but handy question
  • Next by thread: Re: Simply but handy question