---
title: "sum(alongAxes:keepRank:)"
framework: coreml
role: symbol
role_heading: Instance Method
path: "coreml/mltensor/sum(alongaxes:keeprank:)"
---

# sum(alongAxes:keepRank:)

Returns the sum along the specified axes.

## Declaration

```swift
func sum(alongAxes axes: Int..., keepRank: Bool = false) -> MLTensor
```

## Parameters

- `axes`: The axes to reduce.
- `keepRank`: A Boolean indicating whether to keep the reduced axes or not. The default value is false.

## Return Value

Return Value The reduced tensor.

## Discussion

Discussion For example: let x = MLTensor(shape: [3, 2], scalars: [2, 3, 4, 5, 6, 7], scalarType: Float.self) let y = x.sum(alongAxes: 0, keepRank: true) y.shape // is [1, 2] await y.shapedArray(of: Float.self) // is [[12, 15]]

## See Also

### Getting the sum

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