Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I have this matrix

A = {{17/25, 3/25, 5/25, 0, 0}, {5/18, 5/18, 7/18,1/18, 0}, {4/21, 9/21, 4/21, 0, 4/21},    
{0, 0, 3/4, 1/4, 0}, {3/4,1/4, 0, 0, 0}}

And i would like to have this matrix binarize, i wanted it to be like this

{{1, 1, 1, 0, 0}, {1, 1, 1,1, 0}, {1, 1, 1, 0, 1}, {0, 0, 1, 1, 0}, {1, 1, 0, 0, 0}}

Is any function in mathematica that does that? Or I have to programmate it? If so can un help me please?

Thanks (:

share|improve this question

closed as off-topic by Pickett, rasher, Jens, RunnyKine, gpap Jun 11 at 6:54

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – Pickett, rasher, Jens, RunnyKine, gpap
If this question can be reworded to fit the rules in the help center, please edit the question.

2  
Check out Unitize. Unitize@A –  Pickett Jun 11 at 0:15
    
As Pickett says, there is a built-in function in Mathematica that does that: type in Unitize[A]. –  DumpsterDoofus Jun 11 at 0:17
    
Also see Sign and Clip. –  Mr.Wizard Jun 11 at 7:28
    
thanks, search for a while on help and didnt find anything, i was searching with the word matrix :/ –  Mariana da Costa Jun 11 at 10:42

2 Answers 2

up vote 3 down vote accepted

Several Ways. some of them are these:

Unitize@A

or

A /. x_ /; ! x == 0 -> 1

or

A /. x_ /; x != 0 -> 1
share|improve this answer
1  
+1 for Unitize, though the other two solutions could benefit from an x_?NumericQ or similar (x_Integer in this case). If you were to use === and =!= instead of == and != they wouldn't work. –  Szabolcs Jun 11 at 1:20
    
thanks for help :) –  Mariana da Costa Jun 11 at 10:43

Just for fun:

(#/# /. Indeterminate -> 0 // Quiet) &@A
share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.