---
title: "slice(at:)"
framework: coreai
role: symbol
role_heading: Instance Method
path: "coreai/ndarray/mutablerawview/slice(at:)-47fbq"
---

# slice(at:)

Returns a sub-view with the same rank as this view by slicing the dimensions at the provided ranges.

## Declaration

```swift
@export(implementation) consuming func slice<let indexRank : Int>(at ranges: [indexRank of any NDArray.RangeExpression]) -> NDArray.MutableRawView
```

## Parameters

- `ranges`: The range expressions describing where to slice along each dimension. indexRank must be ≤ rank. Unspecified trailing dimensions are assumed to be .all.

## Discussion

Discussion For example if you have a 3D NDArray and want to increment a specific region, you can slice that region, reintroduce the scalar type, and then access a span over it (or use withUnsafeMutablePointer if not contiguous). /// Updates the desired channel and range of rows func incrementRegion(   of mutableRawView: consuming NDArray.MutableRawView,   channel: Int,   startRow: Int,   endRow: Int ) {   var region = mutableRawView.slice(at: [channel, startRow..<endRow, .all]).view(as: Float.self)   var mutableSpan = region.contiguousElements! // contiguous region expected in this case

for i in mutableSpan.indices {     mutableSpan[i] += 1   } } note: If you need to avoid consuming the view which this is called on, you can use mutatingSlice.
