---
title: MLTensor
framework: coreml
role: symbol
role_heading: Structure
path: coreml/mltensor
---

# MLTensor

A multi-dimensional array of numerical or Boolean scalars tailored to ML use cases, containing methods to perform transformations and mathematical operations efficiently using a ML compute device.

## Declaration

```swift
struct MLTensor
```

## Topics

### Creating a tensor

- [init(_:)](coreml/mltensor/init(_:).md)
- [init(_:alongAxis:)](coreml/mltensor/init(_:alongaxis:).md)
- [init(_:scalarType:)](coreml/mltensor/init(_:scalartype:).md)
- [init(bytesNoCopy:shape:scalarType:deallocator:)](coreml/mltensor/init(bytesnocopy:shape:scalartype:deallocator:).md)
- [init(concatenating:alongAxis:)](coreml/mltensor/init(concatenating:alongaxis:).md)
- [init(linearSpaceFrom:through:count:)](coreml/mltensor/init(linearspacefrom:through:count:).md)
- [init(linearSpaceFrom:through:count:scalarType:)](coreml/mltensor/init(linearspacefrom:through:count:scalartype:).md)
- [init(ones:scalarType:)](coreml/mltensor/init(ones:scalartype:).md)
- [init(randomNormal:mean:standardDeviation:seed:scalarType:)](coreml/mltensor/init(randomnormal:mean:standarddeviation:seed:scalartype:).md)
- [init(randomUniform:in:seed:scalarType:)](coreml/mltensor/init(randomuniform:in:seed:scalartype:).md)
- [init(rangeFrom:to:by:)](coreml/mltensor/init(rangefrom:to:by:).md)
- [init(rangeFrom:to:by:scalarType:)](coreml/mltensor/init(rangefrom:to:by:scalartype:).md)
- [init(repeating:shape:)](coreml/mltensor/init(repeating:shape:).md)
- [init(repeating:shape:scalarType:)](coreml/mltensor/init(repeating:shape:scalartype:).md)
- [init(shape:data:scalarType:)](coreml/mltensor/init(shape:data:scalartype:).md)
- [init(shape:scalars:)](coreml/mltensor/init(shape:scalars:).md)
- [init(shape:scalars:scalarType:)](coreml/mltensor/init(shape:scalars:scalartype:).md)
- [init(stacking:alongAxis:)](coreml/mltensor/init(stacking:alongaxis:).md)
- [init(unsafeUninitializedShape:scalarType:initializingWith:)](coreml/mltensor/init(unsafeuninitializedshape:scalartype:initializingwith:).md)
- [init(zeros:scalarType:)](coreml/mltensor/init(zeros:scalartype:).md)

### Accessing tensor properties

- [isScalar](coreml/mltensor/isscalar.md)
- [rank](coreml/mltensor/rank.md)
- [scalarCount](coreml/mltensor/scalarcount.md)
- [scalarType](coreml/mltensor/scalartype.md)
- [shape](coreml/mltensor/shape.md)

### Getting the sum

- [sum(alongAxes:keepRank:)](coreml/mltensor/sum(alongaxes:keeprank:).md)
- [sum(keepRank:)](coreml/mltensor/sum(keeprank:).md)

### Performing a logical AND operation

- [all(alongAxes:keepRank:)](coreml/mltensor/all(alongaxes:keeprank:).md)
- [all(keepRank:)](coreml/mltensor/all(keeprank:).md)

### Performing a logical OR operation

- [any(alongAxes:keepRank:)](coreml/mltensor/any(alongaxes:keeprank:).md)
- [any(keepRank:)](coreml/mltensor/any(keeprank:).md)

### Accessing the indicies

- [argmax()](coreml/mltensor/argmax().md)
- [argmax(alongAxis:keepRank:)](coreml/mltensor/argmax(alongaxis:keeprank:).md)
- [argmin()](coreml/mltensor/argmin().md)
- [argmin(alongAxis:keepRank:)](coreml/mltensor/argmin(alongaxis:keeprank:).md)
- [argsort(alongAxis:descendingOrder:)](coreml/mltensor/argsort(alongaxis:descendingorder:).md)

### Casting the elements

- [cast(like:)](coreml/mltensor/cast(like:).md)
- [cast(to:)](coreml/mltensor/cast(to:).md)

### Computing the absolute, ceiling and floor

- [abs()](coreml/mltensor/abs().md)
- [ceil()](coreml/mltensor/ceil().md)
- [floor()](coreml/mltensor/floor().md)

### Performing arithmetic operations

- [*(_:_:)](coreml/mltensor/*(_:_:).md)
- [*=(_:_:)](coreml/mltensor/*=(_:_:).md)
- [+(_:_:)](coreml/mltensor/+(_:_:).md)
- [+=(_:_:)](coreml/mltensor/+=(_:_:).md)
- [-(_:)](coreml/mltensor/-(_:).md)
- [-(_:_:)](coreml/mltensor/-(_:_:).md)
- [-=(_:_:)](coreml/mltensor/-=(_:_:).md)
- [.!(_:)](coreml/mltensor/'.!(_:).md)
- [.!=(_:_:)](coreml/mltensor/'.!=(_:_:).md)
- [.&(_:_:)](coreml/mltensor/'.&(_:_:).md)
- [.==(_:_:)](coreml/mltensor/'.==(_:_:).md)
- [.>(_:_:)](coreml/mltensor/'._(_:_:)-3m3ro.md)
- [.<(_:_:)](coreml/mltensor/'._(_:_:)-6kfoh.md)
- [.|(_:_:)](coreml/mltensor/'._(_:_:)-7z7ks.md)
- [.^(_:_:)](coreml/mltensor/'._(_:_:)-8il7w.md)
- [.>=(_:_:)](coreml/mltensor/'._=(_:_:)-5qa2u.md)
- [.<=(_:_:)](coreml/mltensor/'._=(_:_:)-otif.md)
- [/(_:_:)](coreml/mltensor/_(_:_:)-5hhe4.md)
- [%(_:_:)](coreml/mltensor/_(_:_:)-7cfjs.md)
- [%=(_:_:)](coreml/mltensor/_=(_:_:)-3xllm.md)
- [/=(_:_:)](coreml/mltensor/_=(_:_:)-53k1k.md)

### Applying trigonometric functions

- [cos()](coreml/mltensor/cos().md)
- [cosh()](coreml/mltensor/cosh().md)
- [acos()](coreml/mltensor/acos().md)
- [acosh()](coreml/mltensor/acosh().md)
- [sin()](coreml/mltensor/sin().md)
- [sinh()](coreml/mltensor/sinh().md)
- [asin()](coreml/mltensor/asin().md)
- [asinh()](coreml/mltensor/asinh().md)
- [tan()](coreml/mltensor/tan().md)
- [tanh()](coreml/mltensor/tanh().md)
- [atan()](coreml/mltensor/atan().md)
- [atanh()](coreml/mltensor/atanh().md)

### Accessing the minimum, maximum and mean

- [min(alongAxes:keepRank:)](coreml/mltensor/min(alongaxes:keeprank:).md)
- [min(keepRank:)](coreml/mltensor/min(keeprank:).md)
- [max(alongAxes:keepRank:)](coreml/mltensor/max(alongaxes:keeprank:).md)
- [max(keepRank:)](coreml/mltensor/max(keeprank:).md)
- [mean(alongAxes:keepRank:)](coreml/mltensor/mean(alongaxes:keeprank:).md)
- [mean(keepRank:)](coreml/mltensor/mean(keeprank:).md)

### Splitting the tensor

- [split(count:alongAxis:)](coreml/mltensor/split(count:alongaxis:).md)
- [split(sizes:alongAxis:)](coreml/mltensor/split(sizes:alongaxis:).md)

### Resizing the tensor

- [resized(to:method:)](coreml/mltensor/resized(to:method:).md)
- [MLTensor.ResizeMethod](coreml/mltensor/resizemethod.md)

### Padding the tensor

- [padded(forSizes:mode:)](coreml/mltensor/padded(forsizes:mode:).md)
- [padded(forSizes:with:)](coreml/mltensor/padded(forsizes:with:).md)
- [MLTensor.PaddingMode](coreml/mltensor/paddingmode.md)

### Replacing the tensor values

- [replacing(atIndices:with:alongAxis:)](coreml/mltensor/replacing(atindices:with:alongaxis:).md)
- [replacing(with:atIndices:alongAxis:)](coreml/mltensor/replacing(with:atindices:alongaxis:).md)
- [replacing(with:where:)](coreml/mltensor/replacing(with:where:).md)

### Gathering slices

- [gathering(atIndices:)](coreml/mltensor/gathering(atindices:).md)
- [gathering(atIndices:alongAxis:)](coreml/mltensor/gathering(atindices:alongaxis:).md)

### Transposing the tensor

- [transposed()](coreml/mltensor/transposed().md)
- [transposed(permutation:)](coreml/mltensor/transposed(permutation:).md)

### Unpacking the tensor

- [unstacked(alongAxis:)](coreml/mltensor/unstacked(alongaxis:).md)

### Getting the shaped representation of the tensor

- [shapedArray(of:)](coreml/mltensor/shapedarray(of:).md)

### Removing dimensions from the shape of the tensor

- [squeezingShape()](coreml/mltensor/squeezingshape().md)
- [squeezingShape(at:)](coreml/mltensor/squeezingshape(at:).md)

### Accessing the product along an axes

- [product(alongAxes:keepRank:)](coreml/mltensor/product(alongaxes:keeprank:).md)
- [product(keepRank:)](coreml/mltensor/product(keeprank:).md)

### Getting the largest values

- [topK(_:)](coreml/mltensor/topk(_:).md)

### Clamping and concatenating

- [clamped(to:)](coreml/mltensor/clamped(to:).md)
- [concatenated(with:alongAxis:)](coreml/mltensor/concatenated(with:alongaxis:).md)

### Computing the cumulative value

- [cumulativeProduct(alongAxis:)](coreml/mltensor/cumulativeproduct(alongaxis:).md)
- [cumulativeSum(alongAxis:)](coreml/mltensor/cumulativesum(alongaxis:).md)

### Computing the exponent, pow and square root

- [exp()](coreml/mltensor/exp().md)
- [exp2()](coreml/mltensor/exp2().md)
- [pow(_:)](coreml/mltensor/pow(_:).md)
- [rsqrt()](coreml/mltensor/rsqrt().md)
- [squared()](coreml/mltensor/squared().md)
- [squareRoot()](coreml/mltensor/squareroot().md)
- [log()](coreml/mltensor/log().md)
- [round()](coreml/mltensor/round().md)
- [matmul(_:)](coreml/mltensor/matmul(_:).md)

### Accessing the extended tensor, sign and reciprocal

- [expandingShape(at:)](coreml/mltensor/expandingshape(at:).md)
- [bandPart(lowerBandCount:upperBandCount:)](coreml/mltensor/bandpart(lowerbandcount:upperbandcount:).md)
- [tiled(multiples:)](coreml/mltensor/tiled(multiples:).md)
- [sign()](coreml/mltensor/sign().md)
- [reciprocal()](coreml/mltensor/reciprocal().md)

### Reshaping the tensor

- [flattened()](coreml/mltensor/flattened().md)
- [reshaped(to:)](coreml/mltensor/reshaped(to:).md)

### Computing the softmax

- [softmax(alongAxis:)](coreml/mltensor/softmax(alongaxis:).md)

### Reversing the tensor

- [reversed(alongAxes:)](coreml/mltensor/reversed(alongaxes:).md)

### Accessing a multiarray’s elements

- [subscript(_:)](coreml/mltensor/subscript(_:).md)
- [subscript(_:_:)](coreml/mltensor/subscript(_:_:).md)
- [subscript(_:_:_:)](coreml/mltensor/subscript(_:_:_:).md)
- [subscript(_:_:_:_:)](coreml/mltensor/subscript(_:_:_:_:).md)
- [subscript(_:_:_:_:_:)](coreml/mltensor/subscript(_:_:_:_:_:).md)

### Default Implementations

- [CustomReflectable Implementations](coreml/mltensor/customreflectable-implementations.md)

## Relationships

### Conforms To

- [Copyable](swift/copyable.md)
- [CustomReflectable](swift/customreflectable.md)
- [CustomStringConvertible](swift/customstringconvertible.md)
- [Escapable](swift/escapable.md)
- [ExpressibleByArrayLiteral](swift/expressiblebyarrayliteral.md)
- [ExpressibleByBooleanLiteral](swift/expressiblebybooleanliteral.md)
- [ExpressibleByFloatLiteral](swift/expressiblebyfloatliteral.md)
- [ExpressibleByIntegerLiteral](swift/expressiblebyintegerliteral.md)
- [Sendable](swift/sendable.md)
- [SendableMetatype](swift/sendablemetatype.md)

## See Also

### Model tensor

- [MLTensorScalar](coreml/mltensorscalar.md)
- [MLTensorRangeExpression](coreml/mltensorrangeexpression.md)
- [pointwiseMin(_:_:)](coreml/pointwisemin(_:_:).md)
- [pointwiseMax(_:_:)](coreml/pointwisemax(_:_:).md)
- [withMLTensorComputePolicy(_:_:)](coreml/withmltensorcomputepolicy(_:_:).md)
