1 of 17

CSE 163

Section AX

TA1 & TA2

Question of the Day: What is your favorite muffin?

How many chihuahuas are in this photo?

2 of 17

Housekeeping 🧼

Important Dates and Reminders

  • THA5 due Tues 5/26 @ 11:59pm
  • Reading Assignment 5 due Tues 5/26 @ 11:59pm.

3 of 17

Game Plan

🏏

What we’ve Learned so far:

  • Numpy!
    • Arrays
    • Operations
    • Images
  • Broadcasting
  • Convolutions

What we’ll cover today:

  • Review numpy basics and convolutions
  • accessibility-simulations.ipynb

3

4 of 17

Convolution Example

4

9

8

7

6

5

4

3

2

1

Image

2

1

Kernel

Output

5 of 17

Convolution Solution

5

9

8

7

6

5

4

3

2

1

Image

2

1

Kernel

2

1

26

Output

6 of 17

Convolution Solution

6

9

8

7

6

5

4

3

2

1

Image

2

1

Kernel

2

26

23

Output

1

7 of 17

Convolution Solution

7

9

8

7

6

5

4

3

2

1

Image

2

1

Kernel

2

1

26

23

17

Output

8 of 17

Convolution Solution

8

9

8

7

6

5

4

3

2

1

Image

2

1

Kernel

2

1

Output

26

23

17

14

8

5

9 of 17

10 of 17

More Generic Formula for Result Size

10

Image

Kernel

width

height

k_height

k_width

(0, 0)

k[0]

k[1]

(1, 0)

(width - k_width, 0)

k[width - k_width]

Total of (width - k_width + 1) kernels because of zero based indexing!

So the shape of the result will be (height - k_height + 1, width - k_width + 1)

11 of 17

Broadcasting with

Problem 2

11

The Rules of Broadcasting

  1. If the two arrays differ in their number of dimensions, the shape of the one with fewer dimensions is padded on it’s left side.
  2. If the shape of two arrays does not match on any dimension, the array with shape equal to 1 in that dimension is stretched to match the other shape.
  3. If in any dimension the sizes disagree and neither is equal to 1, an error is raised.

img.shape = (n, m, 3)

v.shape = (3,)

img.shape = (n, m, 3)

v.shape = (1, 1, 3)

img.shape = (n, m, 3)

v.shape = (n, m, 3)

12 of 17

Word Bank

np.zeros(shape, dtype=float, ...)

  • Returns a new array of given shape and type, filled with zeros

np.ones(shape, dtype=float, ...)

  • Returns a new array of given shape and type, filled with ones

np.arange([start,], stop[,step,], ...)

  • Returns evenly spaced values within a given interval

np.sum(a, ...)

  • Sum of numpy array elements

13 of 17

Practice problems! Open up accessibility-simulations.ipynb

14 of 17

Section code:

15 of 17

Solutions

16 of 17

Solutions pt2

17 of 17

Solutions pt3