<!--
{
  "availability" : [
    "iOS: 27.0.0 -",
    "iPadOS: 27.0.0 -",
    "tvOS: 27.0.0 -",
    "visionOS: 27.0.0 -",
    "watchOS: 27.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "CoreAI",
  "identifier" : "/documentation/CoreAI/NDArray/View",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "Core AI",
      "CoreAI"
    ],
    "preciseIdentifier" : "s:13CoreAIRuntime7NDArrayV4ViewV"
  },
  "title" : "NDArray.View"
}
-->

# NDArray.View

An immutable non-owning view over the contents of a `NDArray`.

```
struct View<Element> where Element : BitwiseCopyable
```

## Topics

### Creating a view

[`init(span: Span<Element>, shape: [Int], strides: [Int])`](/documentation/CoreAI/NDArray/View/init(span:shape:strides:))

Initialize a view from a `Span`.

### Inspecting the view

[`var isContiguous: Bool`](/documentation/CoreAI/NDArray/View/isContiguous)

Returns `true` if the elements in this view have a row-major contiguous layout.

[`var rank: Int`](/documentation/CoreAI/NDArray/View/rank)

The rank of the tensor.

[`var shape: Span<Int>`](/documentation/CoreAI/NDArray/View/shape)

The shape of the tensor.

[`var strides: Span<Int>`](/documentation/CoreAI/NDArray/View/strides)

The strides of the tensor.

[`var interleaveLayout: NDArray.InterleaveLayout?`](/documentation/CoreAI/NDArray/View/interleaveLayout)

Returns which dimension is interleaved, and by what factor it is interleaved. Or returns `nil`
if there is not an interleaved dimension.

### Accessing elements

[`var contiguousElements: Span<Element>?`](/documentation/CoreAI/NDArray/View/contiguousElements)

Returns a `Span` over the backing memory of this view if the memory is in a contiguous layout, otherwise returns `nil`.

[`subscript<let rank : Int>(scalarAt _: InlineArray<rank, Int>) -> Element`](/documentation/CoreAI/NDArray/View/subscript(scalarAt:))

Access the element at a multi-dimensional `index`.

### Accessing memory

[`func withUnsafePointer<R, E>((UnsafePointer<Element>, Span<Int>, Span<Int>) throws(E) -> R) throws(E) -> R`](/documentation/CoreAI/NDArray/View/withUnsafePointer(_:))

Invokes the provided closure with the backing data and memory layout of this view.

### Slicing the view

[`func slice(at: [any NDArray.RangeExpression]) -> NDArray.View<Element>`](/documentation/CoreAI/NDArray/View/slice(at:)-32gsh)

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

[`func slice<let indexRank : Int>(at: [indexRank of any NDArray.RangeExpression]) -> NDArray.View<Element>`](/documentation/CoreAI/NDArray/View/slice(at:)-4yomr)

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

### Converting to a raw view

[`var rawView: NDArray.RawView`](/documentation/CoreAI/NDArray/View/rawView)

Returns a raw view over the same backing data



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)