---
title: "padded(forSizes:mode:)"
framework: coreml
role: symbol
role_heading: Instance Method
path: "coreml/mltensor/padded(forsizes:mode:)"
---

# padded(forSizes:mode:)

Returns a padded tensor according to the specified padding sizes and mode.

## Declaration

```swift
func padded(forSizes sizes: [(before: Int, after: Int)], mode: MLTensor.PaddingMode) -> MLTensor
```

## Parameters

- `sizes`: An array of tuples describing the size to be inserted before and after each dimension.
- `mode`: The mode of padding, etiher constant, reflection, or symmetric.

## Return Value

Return Value The padded tensor.

## Discussion

Discussion For example: let x = MLTensor(shape: [2, 3], scalars: [     1, 2, 3,     4, 5, 6 ], scalarType: Float32.self)

let constantPadding = x.padded(forSizes: [(0, 0), (2, 2)], mode: .constant(Float(0))) // [[0, 0, 1, 2, 3, 0, 0], //  [0, 0, 4, 5, 6, 0, 0]]

let reflectionPadding = x.padded(forSizes: [(0, 0), (2, 2)], mode: .reflection) // [[3, 2, 1, 2, 3, 2, 1], //  [6, 5, 4, 5, 6, 5, 4]]

let symmetricPadding = x.padded(forSizes: [(0, 0), (2, 2)], mode: .symmetric) // [[2, 1, 1, 2, 3, 3, 2], //  [5, 4, 4, 5, 6, 6, 5]]

## See Also

### Padding the tensor

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