# LU decomposition in Julia

**URL:** <https://discourse.julialang.org/t/lu-decomposition-in-julia/77664>\
**Category:** New to Julia\
**Created:** [March 10, 2022, 2:20am UTC](https://discourse.julialang.org/t/lu-decomposition-in-julia/77664 "2022-03-10T02:20:39Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [March 10, 2022, 3:16am UTC](https://discourse.julialang.org/t/lu-decomposition-in-julia/77664/7 "2022-03-10T03:16:20Z")

</div>

> [@lbc546](#):
>
> `U[k,:] `

I think the confusion here is that, even though this is selecting the k-th row of `U`, the result of a 1d slice in Julia is always treated as a “column vector” (i.e. a 1d slice is a 1d array, no matter what dimension is sliced).

So, I think what you want is:

```julia
U[k+1:n,:] = U[k+1:n,:] - L[k+1:n,k]*transpose(U[k,:])

```

to make sure that `U[k,:]` is treated as a row vector for your rank-1 update here.

See also [Unintuitive Julia result: selecting a row from a matrix](https://discourse.julialang.org/t/unintuitive-julia-result-selecting-a-row-from-a-matrix/66222) and [Problem: extracting a row from an array, returns a column](https://discourse.julialang.org/t/problem-extracting-a-row-from-an-array-returns-a-column/37331) and [Trouble Understanding Slicing](https://discourse.julialang.org/t/trouble-understanding-slicing/36821) and [RFC: Drop dimensions indexed by scalars by mbauman · Pull Request #13612 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/pull/13612) (which first implemented this) and [Taking vector transposes seriously · Issue #4774 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/issues/4774#issuecomment-59422003) (where it was proposed as “[APL](https://en.wikipedia.org/wiki/APL_(programming_language))-style indexing”).

---

_[View the full topic](https://discourse.julialang.org/t/lu-decomposition-in-julia/77664)._
