A multidimensional array used as input or output for a model.


Multidimensional arrays are commonly used to represent input and output data. Often, each dimension of a multidimensional array has an associated label or meaning. For example, Core ML neural network models use a C x H x W layout for images, where C is the number of channels, H is the height of the image, and W is the width.

When an MLMultiArray instance of a specific shape and data type is expected as input for a Core ML model, the specifications are defined in an MLMultiArrayConstraint instance associated with the feature's MLFeatureDescription.

All features with type MLFeatureType.multiArray must be provided as an MLMultiArray instance.


Creating a Multidimensional Array

init(shape: [NSNumber], dataType: MLMultiArrayDataType)

Creates a multidimensional array of the given dimensions.

enum MLMultiArrayDataType

The different types the array can hold.

Accessing Values

subscript([NSNumber]) -> NSNumber

Subscript access, with an array of indexes, for the multidimensional array.

subscript(Int) -> NSNumber

Single, linear subscript access for the multidimensional array.

Inspecting the Multidimensional Array

var count: Int

The total number of elements in the multidimensional array.

var dataType: MLMultiArrayDataType

The type of value held in the array.

var shape: [NSNumber]

The array containing the sizes of each dimension of the multidimensional array.

var strides: [NSNumber]

An array containing the number of data elements to step in each dimension, when traversing the array.

var dataPointer: UnsafeMutableRawPointer

Pointer to the underlying buffer holding the elements of the array.


Inherits From

Conforms To

See Also

Model Features

protocol MLFeatureProvider

An interface that represents a collection of feature values for a model.

class MLDictionaryFeatureProvider

A convenience wrapper for the given dictionary of data.

class MLFeatureValue

An immutable instance representing a feature's type and value.

class MLFeatureDescription

A description of a feature.

class MLSequence

A sequence of data used as input or output for a model.

protocol MLBatchProvider

An interface that represents a collection of feature providers.

class MLArrayBatchProvider

A convenience wrapper for batches of feature providers.