({{, (RefLink[Unitize, paclet:ref/Unitize])[x] 
gives 0 when x is zero, and 1 when x has any other numerical value.}})

OpenersNotesSection(Spacer1)Details

(RefLink[Unitize, paclet:ref/Unitize])[x,dx] gives 0 for any x with magnitude less than dx.

(RefLink[Unitize, paclet:ref/Unitize])[x] gives 0 whenever x==0 yields (RefLink[True, paclet:ref/True]).

(RefLink[Unitize, paclet:ref/Unitize])[x] in general works using (RefLink[PossibleZeroQ, paclet:ref/PossibleZeroQ]), and can handle numbers represented in symbolic form.

(RefLink[Unitize, paclet:ref/Unitize]) has attribute (RefLink[Listable, paclet:ref/Listable]).

OpenersPrimaryExamplesSection(Spacer1)Examples  (3)

OpenersExampleSection0(Spacer1)Basic Examples  (2)

Convert numerical values to zero or one:

Unitize[Pi]

Unitize[(Sqrt[2])+(Sqrt[3])-(Sqrt[5+2 (Sqrt[6])])]

Replace values in a matrix with zeros or ones:

m = {{-2,1,0,1},{1,-2,1,0},{0,1,-2,1},{1,0,-2,1}};

Unitize[m]

Show a plot that emphasizes structure:

ArrayPlot[%]

OpenersExampleSection2(Spacer1)Applications  (1)

Determine if a sparse matrix is structurally symmetric:

ArrayPlot[m = SparseArray[{Band[{1,2}]->1,Band[{2,1}]->-1}, {25,25}]]

{SymmetricMatrixQ[m], SymmetricMatrixQ[Unitize[m]]}

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[UnitStep, paclet:ref/UnitStep])  ▪  (RefLink[KroneckerDelta, paclet:ref/KroneckerDelta])  ▪  (RefLink[Boole, paclet:ref/Boole])  ▪  (RefLink[Sign, paclet:ref/Sign])  ▪  (RefLink[DiracDelta, paclet:ref/DiracDelta])  ▪  (RefLink[Clip, paclet:ref/Clip])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Numerical Functions, paclet:guide/NumericalFunctions])}})}})