Contents

index(_:)

Slice the tensor at the specified dimension.

Declaration

static func index(_ index: Int) -> any MLTensorRangeExpression

Discussion

For example:

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

See Also

Slicing the tensor