Contents

range(_:stride:)

Slice the tensor at the specified dimension.

Declaration

static func range(_ range: Range<Int>, stride: Int = 1) -> any MLTensorRangeExpression

Discussion

let x = MLTensor(randomNormal: [1, 3, 28, 28], scalarType: Float.self)
let y = x[..., 0..<2] // or x[..., .range(0..<2, stride: 1)]
y.shape // is [1, 3, 28, 2]

See Also

Slicing the tensor