<!--
{
  "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",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "Core AI"
    ],
    "preciseIdentifier" : "s:13CoreAIRuntime7NDArrayV"
  },
  "title" : "NDArray"
}
-->

# NDArray

A multidimensional array of scalar values used for model inference.

```
struct NDArray
```

## Overview

An `NDArray` stores data in a layout defined by its [`shape`](/documentation/CoreAI/NDArray/shape), [`scalarType`](/documentation/CoreAI/NDArray/scalarType-swift.property),
and [`strides`](/documentation/CoreAI/NDArray/strides).

## Topics

### Creating an array

[`init(shape:scalarType:)`](/documentation/CoreAI/NDArray/init(shape:scalarType:))

Creates an array with the specified shape and scalar type.

[`init(shape:scalarType:strides:)`](/documentation/CoreAI/NDArray/init(shape:scalarType:strides:))

Creates an array with the specified shape, scalar type, and strides.

[`init(shape:scalarType:strides:interleaveLayout:)`](/documentation/CoreAI/NDArray/init(shape:scalarType:strides:interleaveLayout:))

Initialize an NDArray with the provided shape, scalar type, strides, and interleaved dimension.

[`init(scalars:shape:)`](/documentation/CoreAI/NDArray/init(scalars:shape:))

Initialize an ndArray with a copy of some sequence of scalars, stored in the ndArray in row-major order.

[`init(descriptor:)`](/documentation/CoreAI/NDArray/init(descriptor:))

Creates an array with the shape and preferred strides from the specified descriptor.

### Inspecting an array

[`shape`](/documentation/CoreAI/NDArray/shape)

The length of each dimension of the array.

[`scalarType`](/documentation/CoreAI/NDArray/scalarType-swift.property)

The scalar type of the array.

[`strides`](/documentation/CoreAI/NDArray/strides)

The distance, in elements, between consecutive values along each dimension.

[`interleaveLayout`](/documentation/CoreAI/NDArray/interleaveLayout-swift.property)

Returns the interleaved layout of this ndArray, or `nil` if there is no interleave.

### Accessing elements

[`view(as:)`](/documentation/CoreAI/NDArray/view(as:))

Returns a read-only, typed view of this array’s elements.

[`mutableView(as:)`](/documentation/CoreAI/NDArray/mutableView(as:))

Returns a mutable, typed view of this array’s elements.

[`rawView()`](/documentation/CoreAI/NDArray/rawView())

Returns a read-only, raw view of this array’s storage.

[`mutableRawView()`](/documentation/CoreAI/NDArray/mutableRawView())

Returns a mutable, raw view of this array’s storage.

### Accessing views

[`View`](/documentation/CoreAI/NDArray/View)

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

[`MutableView`](/documentation/CoreAI/NDArray/MutableView)

A mutable view over the storage of a tensor.

[`RawView`](/documentation/CoreAI/NDArray/RawView)

A type-erased immutable view over the memory owned by a tensor.

[`MutableRawView`](/documentation/CoreAI/NDArray/MutableRawView)

A type-erased mutable view over the memory owned by a tensor.

### Defining scalar types

[`ScalarType`](/documentation/CoreAI/NDArray/ScalarType-swift.enum)

The possible scalar types.

### Describing interleaved layouts

[`InterleaveLayout`](/documentation/CoreAI/NDArray/InterleaveLayout-swift.struct)

Describes the interleaved memory layout of an ndArray dimension.

### Supporting subscripts

[`RangeExpression`](/documentation/CoreAI/NDArray/RangeExpression)

## Relationships

### Conforms To

[`Sendable`](/documentation/Swift/Sendable)

[`MutableViewRepresentable`](/documentation/CoreAI/InferenceValue/MutableViewRepresentable)

[`ViewRepresentable`](/documentation/CoreAI/InferenceValue/ViewRepresentable)

[`Escapable`](/documentation/Swift/Escapable)

[`SendableMetatype`](/documentation/Swift/SendableMetatype)

---

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)