<!--
{
  "availability" : [
    "iOS: 18.0.0 -",
    "iPadOS: 18.0.0 -",
    "macCatalyst: 18.0.0 -",
    "macOS: 15.0.0 -",
    "tvOS: 18.0.0 -",
    "visionOS: 2.0.0 -",
    "watchOS: 11.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "CoreML",
  "identifier" : "/documentation/CoreML/MLTensor/init(shape:scalars:scalarType:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "Core ML",
      "CoreML"
    ],
    "preciseIdentifier" : "s:6CoreML8MLTensorV5shape7scalars10scalarTypeACSaySiG_q_xmtcAA0C6ScalarRz7ElementQy_RszSlR_r0_lufc"
  },
  "title" : "init(shape:scalars:scalarType:)"
}
-->

# init(shape:scalars:scalarType:)

Creates a tensor with the specified shape and contiguous scalars in row-major order.

```
init<Scalar>(shape: [Int], scalars: some Collection, scalarType: Scalar.Type = Scalar.self) where Scalar : MLTensorScalar
```

## Parameters

`shape`

The dimensions of the tensor.

`scalars`

The scalar contents of the tensor. The product of the dimensions of the shape must equal the number of scalars.

`scalarType`

The scalar type.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)