# How to stop array slice being flattened

**URL:** https://discourse.julialang.org/t/how-to-stop-array-slice-being-flattened/130494
**Category:** General Usage
**Tags:** arrays
**Created:** [July 5, 2025, 3:50pm UTC](https://discourse.julialang.org/t/how-to-stop-array-slice-being-flattened/130494 "2025-07-05T15:50:32Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![user664303](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/user664303/32/37843_2.png) [@user664303](https://discourse.julialang.org/u/user664303)
#### Post date: [July 5, 2025, 3:50pm UTC](https://discourse.julialang.org/t/how-to-stop-array-slice-being-flattened/130494/1 "2025-07-05T15:50:32Z")

</div>

Julia is removing singular dimensions when I slice an array:

```julia
A = reshape([2 2 2 2], 2, 1, 2)
A[1,1,:]
2-element Vector{Int64}:
 2
 2

```

If I want `A` to remain a 1x1x2 array, is there anything I can do other than reshape it again?

---

<div class="post-metadata">

### Author: ![Dan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dan/32/42581_2.png) [@Dan](https://discourse.julialang.org/u/Dan)
#### Post date: [July 5, 2025, 3:53pm UTC](https://discourse.julialang.org/t/how-to-stop-array-slice-being-flattened/130494/2 "2025-07-05T15:53:57Z")

</div>

Is:

```julia
julia> A[1:1,1:1,:]
1×1×2 Array{Int64, 3}:
[:, :, 1] =
 2

[:, :, 2] =
 2

```

good enough?  
General idea: indexing with a single index and not a range removes a dimension from the output.

---

<div class="post-metadata">

### Author: ![user664303](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/user664303/32/37843_2.png) [@user664303](https://discourse.julialang.org/u/user664303)
#### Post date: [July 5, 2025, 4:03pm UTC](https://discourse.julialang.org/t/how-to-stop-array-slice-being-flattened/130494/3 "2025-07-05T16:03:51Z")

</div>

Yes. Thanks, Dan.
