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

# padded(forSizes:with:)

Returns a tensor padded with the given constant according to the specified padding sizes.

## Declaration

```swift
func padded(forSizes sizes: [(before: Int, after: Int)], with value: Float) -> MLTensor
```

## Parameters

- `sizes`: An array of tuples describing the size to be inserted before and after each dimension.
- `value`: The constant value used for padding.

## 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 y = x.padded(forSizes: [(0, 0), (2, 2)], with: 0.0) // [[0, 0, 1, 2, 3, 0, 0], //  [0, 0, 4, 5, 6, 0, 0]]

## See Also

### Padding the tensor

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