---
title: "transpose(dimensions:source:)"
framework: ML Compute
role: symbol
role_heading: Instance Method
platforms: [iOS 14.0+, iPadOS 14.0+, Mac Catalyst 14.0+, macOS 11.0+, tvOS 14.0+]
path: "mlcompute/mlcgraph/transpose(dimensions:source:)"
---

# transpose(dimensions:source:)

Adds a new transpose layer to the graph using the dimensions and source tensor you specify.

## Declaration

```swift
func transpose(dimensions: [Int], source: MLCTensor) -> MLCTensor?
```

## Parameters

- `dimensions`: An array that contains the desired ordering of dimensions.
- `source`: The source tensor.

## Return Value

Return Value A result tensor.

## Discussion

Discussion The dimensions array specifies the input axis source for each output axis. In other words, the nth element in the dimensions array specifies the input axis source for the nth axis in the output. note: The batch dimension is typically axis 0, which you can’t transpose.

## See Also

### Adding New Layers to Graphs

- [split(source:splitCount:dimension:)](mlcompute/mlcgraph/split(source:splitcount:dimension:).md)
- [split(source:splitSectionLengths:dimension:)](mlcompute/mlcgraph/split(source:splitsectionlengths:dimension:).md)
- [concatenate(sources:dimension:)](mlcompute/mlcgraph/concatenate(sources:dimension:).md)
- [reshape(shape:source:)](mlcompute/mlcgraph/reshape(shape:source:).md)
- [gather(withDimension:source:indices:)](mlcompute/mlcgraph/gather(withdimension:source:indices:).md)
- [scatter(withDimension:source:indices:copyFrom:reductionType:)](mlcompute/mlcgraph/scatter(withdimension:source:indices:copyfrom:reductiontype:).md)
