Contents

reshaped(to:)

Returns a new reshaped shaped array.

Declaration

func reshaped(to newShape: [Int]) -> MLShapedArraySlice<Scalar>

Parameters

  • newShape:

    The new shape after reshaping.

Discussion

The reshaped array gets scalars of the original array in first-major order. Therefore, the initializer is semantically equivalent to:

let reshaped = MLShapedArray(scalars: original.scalars, shape: newShape)

Usage example:

let original = MLShapedArraySlice<Int32>(scalars: 0..., shape: [4])
let reshaped = original.reshaped(to: [1, 2, 2])

A scalar can be reshaped to and from a shape where the product of dimensions is one.

The method raises a runtime error if the product of dimensions in the new shape is different from the current one.

See Also

Shaping the array slice