Contents

init(scalars:shape:)

Initialize an ndArray with a copy of some sequence of scalars, stored in the ndArray in row-major order.

Declaration

init<Scalar>(scalars: some Sequence, shape: [Int]) where Scalar : BitwiseCopyable

Parameters

  • scalars:

    A sequence of scalars to be copied into the new ndArray. Note that Scalar must be a type that corresponds to a scalar type found on the NDArray.ScalarType enum.

  • shape:

    The shape of the new ndArray. The ndArray will be stored in row-major order and the scalars will be assigned in row-major order.

Discussion

This utility will construct an ndArray with a copy of the contents of some sequence. For example to make an int32 ndArray with increasing values:

var ndArray = NDArray(scalars: (0..<4) as Range<Int32>, shape: [2, 2])
// The resulting NDArray has contents:
[[0, 1], [2, 3]]