# What is the fastest method to shift matrix?

**URL:** https://discourse.julialang.org/t/what-is-the-fastest-method-to-shift-matrix/85261
**Category:** General Usage
**Tags:** question
**Created:** [August 3, 2022, 7:33pm UTC](https://discourse.julialang.org/t/what-is-the-fastest-method-to-shift-matrix/85261 "2022-08-03T19:33:10Z")
**Posts on this page:** 4
**Page:** 3

<div class="post-metadata">

### Author: ![rocco\_sprmnt21](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rocco_sprmnt21/32/20127_2.png) [@rocco\_sprmnt21](https://discourse.julialang.org/u/rocco_sprmnt21)
#### Post date: [August 5, 2022, 4:27pm UTC](https://discourse.julialang.org/t/what-is-the-fastest-method-to-shift-matrix/85261/41 "2022-08-05T16:27:03Z")

</div>

try if this is faster

```julia
Spshiftl(A,1) .+ B == hcat(A[:,2:end] .+ B[:1,1:end-1], B[:,end])

```

---

<div class="post-metadata">

### Author: ![Amro](https://avatars.discourse-cdn.com/v4/letter/a/4491bb/32.png) [@Amro](https://discourse.julialang.org/u/Amro)
#### Post date: [August 5, 2022, 5:10pm UTC](https://discourse.julialang.org/t/what-is-the-fastest-method-to-shift-matrix/85261/42 "2022-08-05T17:10:01Z")

</div>

Thanks for your explanation. It is clear now.  
Actually, the case is `A .= spshiftl(A,1).+B`

---

<div class="post-metadata">

### Author: ![rocco\_sprmnt21](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rocco_sprmnt21/32/20127_2.png) [@rocco\_sprmnt21](https://discourse.julialang.org/u/rocco_sprmnt21)
#### Post date: [August 5, 2022, 5:37pm UTC](https://discourse.julialang.org/t/what-is-the-fastest-method-to-shift-matrix/85261/43 "2022-08-05T17:37:55Z")

</div>

try if this is faster

```julia
Spshiftl(A,1) .+ B = hcat(A[:,2:end] .+ B[:1,1:end-1], B[:,end])

```

---

<div class="post-metadata">

### Author: ![Amro](https://avatars.discourse-cdn.com/v4/letter/a/4491bb/32.png) [@Amro](https://discourse.julialang.org/u/Amro)
#### Post date: [August 5, 2022, 6:20pm UTC](https://discourse.julialang.org/t/what-is-the-fastest-method-to-shift-matrix/85261/44 "2022-08-05T18:20:23Z")

</div>

I tried but `Spshiftl(A,1)` is faster than `hcat(A[:,2:end] .+ B[:,1:end-1], B[:,end])`

[Previous page](https://discourse.julialang.org/t/what-is-the-fastest-method-to-shift-matrix/85261.md?page=2)
