<!--
{
  "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:data:scalarType:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "Core ML",
      "CoreML"
    ],
    "preciseIdentifier" : "s:6CoreML8MLTensorV5shape4data10scalarTypeACSaySiG_10Foundation4DataVAA0C6Scalar_pXptcfc"
  },
  "title" : "init(shape:data:scalarType:)"
}
-->

# init(shape:data:scalarType:)

Creates a tensor by copying the given block of data.

```
init(shape: [Int], data: Data, scalarType: any MLTensorScalar.Type)
```

## Parameters

`shape`

The shape of the tensor.

`data`

The block of data that holds the contents of the tensor whose data is expected to zero-offset, stored in a C-contiguous
(aka row major) way, and alignment to match the alignment of the scalar type.

`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)