Discrete Wavelets

006 -  The SparseArray Command

Helmut  Knaust - Department of Mathematical Sciences, University of Texas at El Paso, hknaust@utep.edu
02/08/2024

A=SparseArray[{{3,3}->5},{3,3}]

Normal[A]

You make an arrow by typing "-" followed by">"

A=SparseArray[{{i_,i_}->5},{4,3}];
Normal[A]

A=SparseArray[{{i_,j_}->-3},{4,3}];
Normal[A]

A=SparseArray[{{i_,j_}->i+j-1},{4,3}];
Normal[A]

A=SparseArray[{{i_,i_}->5,{4,3}->4},{4,3}];
Normal[A]

First assignment counts:

A=SparseArray[{{i_,i_}->5,{2,2}->4},{4,3}];
Normal[A]

A=SparseArray[{{2,2}->4,{i_,i_}->5},{4,3}];
Normal[A]

“ /; ” means “under the condition” (note the two “=” in the condition):

A=SparseArray[{{i_,j_}/;j==i+1->5},{4,3}];
Normal[A]

A=SparseArray[{{i_,j_}/;i+j==5->3},{4,4}];
Normal[A]

A=SparseArray[{{i_,j_}/;j+i==5->5,{i_,i_}->1},{4,4}];
Normal[A]

A=SparseArray[{{i_,i_}->1,{i_,j_}/;j+i==6->5},{5,5}];
Normal[A]

A=SparseArray[{{i_,j_}/;j+i==6->5,{i_,i_}->1},{5,5}];
Normal[A]

A=SparseArray[{{i_,j_}/;i==2j-1->1/2,{i_,j_}/;i==2j->1/2},{8,4}];
Normal[A]
Normal[Transpose[A]]

An Application: Averaging

pic=RandomInteger[{0,255},{8,10}]

A=SparseArray[{{i_,j_}/;i==2j-1->1/2.,{i_,j_}/;i==2j->1/2.},{10,5}];Normal[A]

pic.A

B=Transpose[SparseArray[{{i_,j_}/;i==2j-1->1/2.,{i_,j_}/;i==2j->1/2.},{8,4}]];Normal[B]

B.pic.A

SetDirectory[NotebookDirectory[]];
<<DW.wl

pic=Import["Images\\Grayscale\\landscape.png","Data"];
ImagePlot[pic]

{dimr,dimc}=Dimensions[pic]

A=SparseArray[{{i_,j_}/;i==2j-1->1/2,{i_,j_}/;i==2j->1/2},{dimc,dimc/2}];

ImagePlot[pic.A]

B=Transpose[SparseArray[{{i_,j_}/;i==2j-1->1/2,{i_,j_}/;i==2j->1/2},{dimr,dimr/2}]];

ImagePlot[pic2=B.pic.A]

Dimensions[pic2]