Y’all gonna see a lot from me cuz i dunno what the fuck i’m doing :). Working on problem set 2 of the MIT course and i’ve hit a wall. The question is:
Write a function box_blur(v, l)
that blurs a vector v
with a window of length l
by averaging the elements within a window from -l
to l
. This is called a box blur. Use your function extend
to handle the boundaries correctly.
Return a vector of the same size as v
.
My extend function is:
function extend(v::AbstractVector, i)
n = length(v)
if i in 1:n
return v[i]
elseif i < 1
return v[1]
else
return v[n]
end
end
my mean function is
function mean(v)
total = 0
n = length(v)
for s in 1:n
total += v[s]
end
return total / n
end
my initial just straight up non-programmer logic for the box blur was:
function box_blur(v::AbstractArray, l)
vn = copy(v)
n = length(v)
for i in vn
window = i-l:i+l
vn[i] = mean(extend(window, i))
end
return vn
end
I still end up with “ArgumentError: invalid index: 1.0 of type Float64” so i know the code must be nonsense but I don’t know how to incorporate the extend function to ensure the proper boundary.