---
title: "changingLayout(to:)"
framework: coreml
role: symbol
role_heading: Instance Method
path: "coreml/mlshapedarray/changinglayout(to:)"
---

# changingLayout(to:)

Returns a copy with the specified buffer layout.

## Declaration

```swift
func changingLayout(to bufferLayout: MLShapedArrayBufferLayout) -> MLShapedArray<Scalar>
```

## Parameters

- `bufferLayout`: The desired buffer layout.

## Discussion

Discussion The returned shaped array will have .strides property according to the requested layout. The function may return a heap-memory backed shaped array even if self is backed by a pixel buffer. let source = MLShapedArray<Int32>(scalars: 0..., shape: [2, 2])

// Returns a new MLShapedArray with the specified strides. _ = source.changingLayout(to: .custom(strides: [4, 1]))

// Returns a new MLShapedArray with the first-major contiguous layout. _ = source.changingLayout(to: .firstMajorContiguous)

// Returns a new MLShapedArray with the last-major contiguous layout. _ = source.changingLayout(to: .lastMajorContiguous) The withUnsafeShapedBufferPointer function provides read-only access to the underlying buffer of the layout. The withUnsafeMutableShapedBufferPointer(body:) function may provide a buffer of different layout due to copy-on-write. Use withUnsafeMutableShapedBufferPointer(bufferLayout:body:) if you need a specific buffer layout. It raises a precondition error if the custom strides and the shape have different ranks.

## See Also

### Shaping the array

- [expandingShape(at:)](coreml/mlshapedarray/expandingshape(at:).md)
- [reshaped(to:)](coreml/mlshapedarray/reshaped(to:).md)
- [squeezingShape()](coreml/mlshapedarray/squeezingshape().md)
- [transposed()](coreml/mlshapedarray/transposed().md)
- [transposed(permutation:)](coreml/mlshapedarray/transposed(permutation:).md)
