---
title: "cast(like:)"
framework: coreml
role: symbol
role_heading: Instance Method
path: "coreml/mltensor/cast(like:)"
---

# cast(like:)

Casts the elements of the tensor to the scalar type of the given array.

## Declaration

```swift
func cast(like other: MLTensor) -> MLTensor
```

## Parameters

- `other`: The other tensor whose scalar type is used for the cast.

## Return Value

Return Value A new tensor with its contents cast to the scalar type of other.

## Discussion

Discussion For example: let x = MLTensor([1, 2, 3], scalarType: Float.self) let y = MLTensor([1, 2, 3], scalarType: Int32.self) let z = y.cast(like: x) z.scalarType // is Float

## See Also

### Casting the elements

- [cast(to:)](coreml/mltensor/cast(to:).md)
