# Trouble Understanding Slicing

**URL:** <https://discourse.julialang.org/t/trouble-understanding-slicing/36821>\
**Category:** New to Julia\
**Created:** [March 31, 2020, 9:30pm UTC](https://discourse.julialang.org/t/trouble-understanding-slicing/36821 "2020-03-31T21:30:29Z")\
**Posts on this page:** 1\
**Showing post:** 8

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [April 1, 2020, 2:46pm UTC](https://discourse.julialang.org/t/trouble-understanding-slicing/36821/8 "2020-04-01T14:46:07Z")

</div>

The reason scalar indexing drops dimensions is a little more subtle than I explained initially. The idea is that `A[i,:][j]=A[i,j]` is an identity that feels like it should hold. Since `A[i,j]` is a scalar, `A[i,:]` needs to be a type which when indexed by 1 index gives a scalar. The fact that Julia has ND arrays makes this harder to get around since matrices aren’t consider special-- they are just `Array{T,2}`.

The reason `A[[i],:]` needs to have the same type as `A[[i,j],:]` is for type stability. Both of these are calls to `getindex(::Vector{Int}, ::COLON_TYPE)`, so if you want type stable code (which is critical for performance) both of these need to have the same type.

---

_[View the full topic](https://discourse.julialang.org/t/trouble-understanding-slicing/36821)._
