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

# sum(keepRank:)

Returns the sum along all axes.

## Declaration

```swift
func sum(keepRank: Bool = false) -> MLTensor
```

## Parameters

- `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() y.shape // is [] await y.shapedArray(of: Float.self) // is [27]

## See Also

### Getting the sum

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