<!--
{
  "availability" : [
    "iOS: 11.0.0 -",
    "iPadOS: 11.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.13.0 -",
    "tvOS: 11.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 4.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "CoreML",
  "identifier" : "/documentation/CoreML/MLMultiArray",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "Core ML"
    ],
    "preciseIdentifier" : "c:objc(cs)MLMultiArray"
  },
  "title" : "MLMultiArray"
}
-->

# MLMultiArray

A machine learning collection type that stores numeric values in an array with multiple dimensions.

```
class MLMultiArray
```

## Overview

A multidimensional array, or *multiarray*, is one of the underlying types of an `MLFeatureValue` that stores numeric values in multiple dimensions. All elements in an [`MLMultiArray`](/documentation/CoreML/MLMultiArray) instance are one of the same type, and one of the types that [`MLMultiArrayDataType`](/documentation/CoreML/MLMultiArrayDataType) defines:

- [`MLMultiArrayDataType.int32`](/documentation/CoreML/MLMultiArrayDataType/int32): 32-bit integer
- [`MLMultiArrayDataType.float16`](/documentation/CoreML/MLMultiArrayDataType/float16): 16-bit floating point number
- [`MLMultiArrayDataType.float32`](/documentation/CoreML/MLMultiArrayDataType/float32): 32-bit floating point number (also known as [`float`](/documentation/CoreML/MLMultiArrayDataType/float))
- [`float64`](/documentation/CoreML/MLMultiArrayDataType/float64): 64-bit floating point number (also known as `double` in Swift or `MLMultiArrayDataTypeDouble` in Objective-C)

Each dimension in a multiarray is typically significant or meaningful. For example, a model could have an input that accepts images as a multiarray of pixels with three dimensions, C x H x W. The first dimension, *C*,_ _represents the number of color channels, and the second and third dimensions, *H* and *W*, represent the image’s height and width, respectively. The number of dimensions and size of each dimension define the multiarray’s *shape*.

> Note:
> Some models use a one-dimensional multiarray for an input or output. This type of multiarray is conceptually identical to a conventional array.

The [`shape`](/documentation/CoreML/MLMultiArray/shape) property is an integer array that has an element for each dimension in the multiarray. Each element in [`shape`](/documentation/CoreML/MLMultiArray/shape) defines the size of the corresponding dimension. To inspect the shape and constraints of a model’s multiarray input or output feature:

1. Access the model’s [`modelDescription`](/documentation/CoreML/MLModel/modelDescription) property.
2. Find the multiarray input or output feature in the model description’s [`inputDescriptionsByName`](/documentation/CoreML/MLModelDescription/inputDescriptionsByName) or [`outputDescriptionsByName`](/documentation/CoreML/MLModelDescription/outputDescriptionsByName) property, respectively.
3. Access the feature description’s [`multiArrayConstraint`](/documentation/CoreML/MLFeatureDescription/multiArrayConstraint) property.
4. Inspect the multiarray constraint’s [`shape`](/documentation/CoreML/MLMultiArrayConstraint/shape) and [`shapeConstraint`](/documentation/CoreML/MLMultiArrayConstraint/shapeConstraint).

## Topics

### Creating a multiarray

[`init(_:)`](/documentation/CoreML/MLMultiArray/init(_:))

An MLMultiArray constructed with the FixedWidthInteger elements of the collection
converted to Int32.

[`init(shape:dataType:)`](/documentation/CoreML/MLMultiArray/init(shape:dataType:))

Creates a multidimensional array with a shape and type.

[`init(shape:dataType:strides:)`](/documentation/CoreML/MLMultiArray/init(shape:dataType:strides:))

Creates the object with specified strides.

[`initWithShape:dataType:strides:`](/documentation/CoreML/MLMultiArray/initWithShape:dataType:strides:)

Creates the object with specified strides.

[`init(dataPointer:shape:dataType:strides:deallocator:)`](/documentation/CoreML/MLMultiArray/init(dataPointer:shape:dataType:strides:deallocator:))

Creates a multiarray from a data pointer.

[`init(byConcatenatingMultiArrays:alongAxis:dataType:)`](/documentation/CoreML/MLMultiArray/init(byConcatenatingMultiArrays:alongAxis:dataType:))

Merges an array of multiarrays into one multiarray along an axis.

[`init(pixelBuffer:shape:)`](/documentation/CoreML/MLMultiArray/init(pixelBuffer:shape:))

Creates a multiarray sharing the surface of a pixel buffer.

[`MLMultiArrayDataType`](/documentation/CoreML/MLMultiArrayDataType)

Constants that define the underlying element types a multiarray can store.

### Inspecting a multiarray

[`count`](/documentation/CoreML/MLMultiArray/count)

The total number of elements in the multiarray.

[`dataType`](/documentation/CoreML/MLMultiArray/dataType)

The underlying type of the multiarray.

[`shape`](/documentation/CoreML/MLMultiArray/shape)

The multiarray’s multidimensional shape as a number array in which each element’s value is the size of the corresponding dimension.

[`strides`](/documentation/CoreML/MLMultiArray/strides)

A number array in which each element is the number of memory locations that span the length of the corresponding dimension.

### Transfering the contents

[`transfer(to:)`](/documentation/CoreML/MLMultiArray/transfer(to:))

Transfer the contents to the destination multi-array.

### Providing buffer access

[`withUnsafeBufferPointer(ofType:_:)`](/documentation/CoreML/MLMultiArray/withUnsafeBufferPointer(ofType:_:))

Calls a given closure with a raw pointer to the multiarray’s storage.

[`withUnsafeBytes(_:)`](/documentation/CoreML/MLMultiArray/withUnsafeBytes(_:))

Calls a given closure with a raw pointer to the multiarray’s storage.

[`withUnsafeMutableBufferPointer(ofType:_:)`](/documentation/CoreML/MLMultiArray/withUnsafeMutableBufferPointer(ofType:_:))

Calls a given closure with a raw pointer to the multiarray’s mutable storage.

[`withUnsafeMutableBytes(_:)`](/documentation/CoreML/MLMultiArray/withUnsafeMutableBytes(_:))

Calls a given closure with a raw pointer to the multiarray’s mutable storage.

### Accessing a multiarray’s elements

[`subscript(_:)`](/documentation/CoreML/MLMultiArray/subscript(_:))

[`setObject:atIndexedSubscript:`](/documentation/CoreML/MLMultiArray/setObject:atIndexedSubscript:)

Assigns a number to the multiarray’s element at the location that the linear offset defines.

[`setObject:forKeyedSubscript:`](/documentation/CoreML/MLMultiArray/setObject:forKeyedSubscript:)

Assigns a number to the multiarray’s element at the location that the number array defines.

[`getBytesWithHandler:`](/documentation/CoreML/MLMultiArray/getBytesWithHandler:)

Get the underlying buffer pointer to read.

[`getMutableBytesWithHandler:`](/documentation/CoreML/MLMultiArray/getMutableBytesWithHandler:)

Get the underlying buffer pointer to mutate.

[`pixelBuffer`](/documentation/CoreML/MLMultiArray/pixelBuffer)

A reference to the multiarray’s underlying pixel buffer.

[`dataPointer`](/documentation/CoreML/MLMultiArray/dataPointer)

A pointer to the multiarray’s underlying memory.



---

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)