# Converting python code into julia code

**URL:** <https://discourse.julialang.org/t/converting-python-code-into-julia-code/98991>\
**Category:** General Usage\
**Tags:** python, convert, signal-processing\
**Created:** [May 17, 2023, 10:55am UTC](https://discourse.julialang.org/t/converting-python-code-into-julia-code/98991 "2023-05-17T10:55:38Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![GunnarFarneback](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gunnarfarneback/32/1827_2.png) [@GunnarFarneback](https://discourse.julialang.org/u/GunnarFarneback)\
**Post date:** [May 17, 2023, 12:49pm UTC](https://discourse.julialang.org/t/converting-python-code-into-julia-code/98991/7 "2023-05-17T12:49:41Z")

</div>

I would focus on the desired output and try to achieve that as straightforwardly as possible, rather than trying to port some other implementation designed for a system with other performance characteristics. In this case it’s all a matter of filling an array with entries from a vector, so just do a double loop.

```julia
function buffer(X, n, p)
    0 <= p < n || error("You must have 0 <= p < n.")
    m = cld(length(X), n - p)
    out = zeros(eltype(X), n, m)
    for j = 1:m
        for i = 1:n
            k = (j - 1) * (n - p) + i - p
            if k in eachindex(X)
                out[i, j] = X[k]
            end
        end
    end
    return out
end

```

---

_[View the full topic](https://discourse.julialang.org/t/converting-python-code-into-julia-code/98991)._
