> For the complete documentation index, see [llms.txt](https://boinc-ai.gitbook.io/transformers.js/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://boinc-ai.gitbook.io/transformers.js/api-reference/utilities/tensor.md).

# Tensor

## utils/tensor

Helper module for `Tensor` processing.

These functions and classes are only used internally, meaning an end-user shouldn’t need to access anything here.

* [utils/tensor](https://huggingface.co/docs/transformers.js/api/utils/tensor#module_utils/tensor)
  * *static*
    * [.Tensor](https://huggingface.co/docs/transformers.js/api/utils/tensor#module_utils/tensor.Tensor)
      * [`new Tensor(...args)`](https://huggingface.co/docs/transformers.js/api/utils/tensor#new_module_utils/tensor.Tensor_new)
      * [`.Symbol.iterator()`](https://huggingface.co/docs/transformers.js/api/utils/tensor#module_utils/tensor.Tensor+Symbol.iterator) ⇒ `Iterator`
      * [`._getitem(index)`](https://huggingface.co/docs/transformers.js/api/utils/tensor#module_utils/tensor.Tensor+_getitem) ⇒ `Tensor`
      * [`.indexOf(item)`](https://huggingface.co/docs/transformers.js/api/utils/tensor#module_utils/tensor.Tensor+indexOf) ⇒ `number`
      * [`._subarray(index, iterSize, iterDims)`](https://huggingface.co/docs/transformers.js/api/utils/tensor#module_utils/tensor.Tensor+_subarray) ⇒ `Tensor`
      * [`.item()`](https://huggingface.co/docs/transformers.js/api/utils/tensor#module_utils/tensor.Tensor+item) ⇒ `number`
      * [`.tolist()`](https://huggingface.co/docs/transformers.js/api/utils/tensor#module_utils/tensor.Tensor+tolist) ⇒ `Array`
      * [`.sigmoid()`](https://huggingface.co/docs/transformers.js/api/utils/tensor#module_utils/tensor.Tensor+sigmoid) ⇒ `Tensor`
      * [`.sigmoid_()`](https://huggingface.co/docs/transformers.js/api/utils/tensor#module_utils/tensor.Tensor+sigmoid_) ⇒ `Tensor`
      * [`.transpose(...dims)`](https://huggingface.co/docs/transformers.js/api/utils/tensor#module_utils/tensor.Tensor+transpose) ⇒ `Tensor`
      * [`.sum([dim], keepdim)`](https://huggingface.co/docs/transformers.js/api/utils/tensor#module_utils/tensor.Tensor+sum) ⇒
      * [`.norm([p], [dim], [keepdim])`](https://huggingface.co/docs/transformers.js/api/utils/tensor#module_utils/tensor.Tensor+norm) ⇒ `Tensor`
      * [`.normalize_([p], [dim])`](https://huggingface.co/docs/transformers.js/api/utils/tensor#module_utils/tensor.Tensor+normalize_) ⇒ `Tensor`
      * [`.normalize([p], [dim])`](https://huggingface.co/docs/transformers.js/api/utils/tensor#module_utils/tensor.Tensor+normalize) ⇒ `Tensor`
      * [`.stride()`](https://huggingface.co/docs/transformers.js/api/utils/tensor#module_utils/tensor.Tensor+stride) ⇒ `Array.<number>`
      * [`.squeeze([dim])`](https://huggingface.co/docs/transformers.js/api/utils/tensor#module_utils/tensor.Tensor+squeeze) ⇒
      * [`.squeeze_()`](https://huggingface.co/docs/transformers.js/api/utils/tensor#module_utils/tensor.Tensor+squeeze_)
      * [`.unsqueeze(dim)`](https://huggingface.co/docs/transformers.js/api/utils/tensor#module_utils/tensor.Tensor+unsqueeze) ⇒
      * [`.unsqueeze_()`](https://huggingface.co/docs/transformers.js/api/utils/tensor#module_utils/tensor.Tensor+unsqueeze_)
      * [`.flatten_()`](https://huggingface.co/docs/transformers.js/api/utils/tensor#module_utils/tensor.Tensor+flatten_)
      * [`.flatten(start_dim, end_dim)`](https://huggingface.co/docs/transformers.js/api/utils/tensor#module_utils/tensor.Tensor+flatten) ⇒
      * [`.view(...dims)`](https://huggingface.co/docs/transformers.js/api/utils/tensor#module_utils/tensor.Tensor+view) ⇒ `Tensor`
    * [`.transpose(tensor, axes)`](https://huggingface.co/docs/transformers.js/api/utils/tensor#module_utils/tensor.transpose) ⇒ `Tensor`
    * [`.interpolate(input, size, mode, align_corners)`](https://huggingface.co/docs/transformers.js/api/utils/tensor#module_utils/tensor.interpolate) ⇒ `Tensor`
    * [`.mean_pooling(last_hidden_state, attention_mask)`](https://huggingface.co/docs/transformers.js/api/utils/tensor#module_utils/tensor.mean_pooling) ⇒ `Tensor`
    * [`.cat(tensors, dim)`](https://huggingface.co/docs/transformers.js/api/utils/tensor#module_utils/tensor.cat) ⇒ `Tensor`
    * [`.stack(tensors, dim)`](https://huggingface.co/docs/transformers.js/api/utils/tensor#module_utils/tensor.stack) ⇒ `Tensor`
    * [`.std_mean(input, dim, correction, keepdim)`](https://huggingface.co/docs/transformers.js/api/utils/tensor#module_utils/tensor.std_mean) ⇒ `Array.<Tensor>`
    * [`.mean(input, dim, keepdim)`](https://huggingface.co/docs/transformers.js/api/utils/tensor#module_utils/tensor.mean) ⇒
    * [`.dynamicTimeWarping(matrix)`](https://huggingface.co/docs/transformers.js/api/utils/tensor#module_utils/tensor.dynamicTimeWarping) ⇒ `Array.<Array<number>>`
    * [`.ones(size)`](https://huggingface.co/docs/transformers.js/api/utils/tensor#module_utils/tensor.ones)
    * [`.ones_like(tensor)`](https://huggingface.co/docs/transformers.js/api/utils/tensor#module_utils/tensor.ones_like) ⇒
  * *inner*
    * [`~ONNXTensor`](https://huggingface.co/docs/transformers.js/api/utils/tensor#module_utils/tensor..ONNXTensor) : `Object`
    * [`~reshape(data, dimensions)`](https://huggingface.co/docs/transformers.js/api/utils/tensor#module_utils/tensor..reshape) ⇒ `*`
      * [`~reshapedArray`](https://huggingface.co/docs/transformers.js/api/utils/tensor#module_utils/tensor..reshape..reshapedArray) : `any`
    * [`~DataArray`](https://huggingface.co/docs/transformers.js/api/utils/tensor#module_utils/tensor..DataArray) : `*`
    * [`~NestArray`](https://huggingface.co/docs/transformers.js/api/utils/tensor#module_utils/tensor..NestArray) : `*`

***

### utils/tensor.Tensor

**Kind**: static class of [`utils/tensor`](https://huggingface.co/docs/transformers.js/api/utils/tensor#module_utils/tensor)

* [.Tensor](https://huggingface.co/docs/transformers.js/api/utils/tensor#module_utils/tensor.Tensor)
  * [`new Tensor(...args)`](https://huggingface.co/docs/transformers.js/api/utils/tensor#new_module_utils/tensor.Tensor_new)
  * [`.Symbol.iterator()`](https://huggingface.co/docs/transformers.js/api/utils/tensor#module_utils/tensor.Tensor+Symbol.iterator) ⇒ `Iterator`
  * [`._getitem(index)`](https://huggingface.co/docs/transformers.js/api/utils/tensor#module_utils/tensor.Tensor+_getitem) ⇒ `Tensor`
  * [`.indexOf(item)`](https://huggingface.co/docs/transformers.js/api/utils/tensor#module_utils/tensor.Tensor+indexOf) ⇒ `number`
  * [`._subarray(index, iterSize, iterDims)`](https://huggingface.co/docs/transformers.js/api/utils/tensor#module_utils/tensor.Tensor+_subarray) ⇒ `Tensor`
  * [`.item()`](https://huggingface.co/docs/transformers.js/api/utils/tensor#module_utils/tensor.Tensor+item) ⇒ `number`
  * [`.tolist()`](https://huggingface.co/docs/transformers.js/api/utils/tensor#module_utils/tensor.Tensor+tolist) ⇒ `Array`
  * [`.sigmoid()`](https://huggingface.co/docs/transformers.js/api/utils/tensor#module_utils/tensor.Tensor+sigmoid) ⇒ `Tensor`
  * [`.sigmoid_()`](https://huggingface.co/docs/transformers.js/api/utils/tensor#module_utils/tensor.Tensor+sigmoid_) ⇒ `Tensor`
  * [`.transpose(...dims)`](https://huggingface.co/docs/transformers.js/api/utils/tensor#module_utils/tensor.Tensor+transpose) ⇒ `Tensor`
  * [`.sum([dim], keepdim)`](https://huggingface.co/docs/transformers.js/api/utils/tensor#module_utils/tensor.Tensor+sum) ⇒
  * [`.norm([p], [dim], [keepdim])`](https://huggingface.co/docs/transformers.js/api/utils/tensor#module_utils/tensor.Tensor+norm) ⇒ `Tensor`
  * [`.normalize_([p], [dim])`](https://huggingface.co/docs/transformers.js/api/utils/tensor#module_utils/tensor.Tensor+normalize_) ⇒ `Tensor`
  * [`.normalize([p], [dim])`](https://huggingface.co/docs/transformers.js/api/utils/tensor#module_utils/tensor.Tensor+normalize) ⇒ `Tensor`
  * [`.stride()`](https://huggingface.co/docs/transformers.js/api/utils/tensor#module_utils/tensor.Tensor+stride) ⇒ `Array.<number>`
  * [`.squeeze([dim])`](https://huggingface.co/docs/transformers.js/api/utils/tensor#module_utils/tensor.Tensor+squeeze) ⇒
  * [`.squeeze_()`](https://huggingface.co/docs/transformers.js/api/utils/tensor#module_utils/tensor.Tensor+squeeze_)
  * [`.unsqueeze(dim)`](https://huggingface.co/docs/transformers.js/api/utils/tensor#module_utils/tensor.Tensor+unsqueeze) ⇒
  * [`.unsqueeze_()`](https://huggingface.co/docs/transformers.js/api/utils/tensor#module_utils/tensor.Tensor+unsqueeze_)
  * [`.flatten_()`](https://huggingface.co/docs/transformers.js/api/utils/tensor#module_utils/tensor.Tensor+flatten_)
  * [`.flatten(start_dim, end_dim)`](https://huggingface.co/docs/transformers.js/api/utils/tensor#module_utils/tensor.Tensor+flatten) ⇒
  * [`.view(...dims)`](https://huggingface.co/docs/transformers.js/api/utils/tensor#module_utils/tensor.Tensor+view) ⇒ `Tensor`

***

#### new Tensor(...args)

Create a new Tensor or copy an existing Tensor.

| Param   | Type |
| ------- | ---- |
| ...args | `*`  |

***

#### tensor.Symbol.iterator() ⇒ \<code> Iterator \</code>

Returns an iterator object for iterating over the tensor data in row-major order. If the tensor has more than one dimension, the iterator will yield subarrays.

**Kind**: instance method of [`Tensor`](https://huggingface.co/docs/transformers.js/api/utils/tensor#module_utils/tensor.Tensor)\
**Returns**: `Iterator` - An iterator object for iterating over the tensor data in row-major order.

***

#### tensor.\_getitem(index) ⇒ \<code> Tensor \</code>

Index into a Tensor object.

**Kind**: instance method of [`Tensor`](https://huggingface.co/docs/transformers.js/api/utils/tensor#module_utils/tensor.Tensor)\
**Returns**: `Tensor` - The data at the specified index.

| Param | Type     | Description          |
| ----- | -------- | -------------------- |
| index | `number` | The index to access. |

***

#### tensor.indexOf(item) ⇒ \<code> number \</code>

**Kind**: instance method of [`Tensor`](https://huggingface.co/docs/transformers.js/api/utils/tensor#module_utils/tensor.Tensor)\
**Returns**: `number` - The index of the first occurrence of item in the tensor data.

| Param | Type                 | Description                          |
| ----- | -------------------- | ------------------------------------ |
| item  | `number` \| `bigint` | The item to search for in the tensor |

***

#### tensor.\_subarray(index, iterSize, iterDims) ⇒ \<code> Tensor \</code>

**Kind**: instance method of [`Tensor`](https://huggingface.co/docs/transformers.js/api/utils/tensor#module_utils/tensor.Tensor)

| Param    | Type     |
| -------- | -------- |
| index    | `number` |
| iterSize | `number` |
| iterDims | `any`    |

***

#### tensor.item() ⇒ \<code> number \</code>

Returns the value of this tensor as a standard JavaScript Number. This only works for tensors with one element. For other cases, see `Tensor.tolist()`.

**Kind**: instance method of [`Tensor`](https://huggingface.co/docs/transformers.js/api/utils/tensor#module_utils/tensor.Tensor)\
**Returns**: `number` - The value of this tensor as a standard JavaScript Number.\
**Throws**:

* `Error` If the tensor has more than one element.

***

#### tensor.tolist() ⇒ \<code> Array \</code>

Convert tensor data to a n-dimensional JS list

**Kind**: instance method of [`Tensor`](https://huggingface.co/docs/transformers.js/api/utils/tensor#module_utils/tensor.Tensor)

***

#### tensor.sigmoid() ⇒ \<code> Tensor \</code>

Return a new Tensor with the sigmoid function applied to each element.

**Kind**: instance method of [`Tensor`](https://huggingface.co/docs/transformers.js/api/utils/tensor#module_utils/tensor.Tensor)\
**Returns**: `Tensor` - The tensor with the sigmoid function applied.

***

#### tensor.sigmoid\_() ⇒ \<code> Tensor \</code>

Applies the sigmoid function to the tensor in place.

**Kind**: instance method of [`Tensor`](https://huggingface.co/docs/transformers.js/api/utils/tensor#module_utils/tensor.Tensor)\
**Returns**: `Tensor` - Returns `this`.

***

#### tensor.transpose(...dims) ⇒ \<code> Tensor \</code>

Return a transposed version of this Tensor, according to the provided dimensions.

**Kind**: instance method of [`Tensor`](https://huggingface.co/docs/transformers.js/api/utils/tensor#module_utils/tensor.Tensor)\
**Returns**: `Tensor` - The transposed tensor.

| Param   | Type     | Description              |
| ------- | -------- | ------------------------ |
| ...dims | `number` | Dimensions to transpose. |

***

#### tensor.sum(\[dim], keepdim) ⇒

Returns the sum of each row of the input tensor in the given dimension dim.

**Kind**: instance method of [`Tensor`](https://huggingface.co/docs/transformers.js/api/utils/tensor#module_utils/tensor.Tensor)\
**Returns**: The summed tensor

| Param   | Type      | Default | Description                                                                   |
| ------- | --------- | ------- | ----------------------------------------------------------------------------- |
| \[dim]  | `number`  |         | The dimension or dimensions to reduce. If `null`, all dimensions are reduced. |
| keepdim | `boolean` | `false` | Whether the output tensor has `dim` retained or not.                          |

***

#### tensor.norm(\[p], \[dim], \[keepdim]) ⇒ \<code> Tensor \</code>

Returns the matrix norm or vector norm of a given tensor.

**Kind**: instance method of [`Tensor`](https://huggingface.co/docs/transformers.js/api/utils/tensor#module_utils/tensor.Tensor)\
**Returns**: `Tensor` - The norm of the tensor.

| Param      | Type                 | Default | Description                                                                                                                                       |
| ---------- | -------------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------- |
| \[p]       | `number` \| `string` | `'fro'` | The order of norm                                                                                                                                 |
| \[dim]     | `number`             |         | Specifies which dimension of the tensor to calculate the norm across. If dim is None, the norm will be calculated across all dimensions of input. |
| \[keepdim] | `boolean`            | `false` | Whether the output tensors have dim retained or not.                                                                                              |

***

#### tensor.normalize\_(\[p], \[dim]) ⇒ \<code> Tensor \</code>

Performs `L_p` normalization of inputs over specified dimension. Operates in place.

**Kind**: instance method of [`Tensor`](https://huggingface.co/docs/transformers.js/api/utils/tensor#module_utils/tensor.Tensor)\
**Returns**: `Tensor` - `this` for operation chaining.

| Param  | Type     | Default | Description                                |
| ------ | -------- | ------- | ------------------------------------------ |
| \[p]   | `number` | `2`     | The exponent value in the norm formulation |
| \[dim] | `number` | `1`     | The dimension to reduce                    |

***

#### tensor.normalize(\[p], \[dim]) ⇒ \<code> Tensor \</code>

Performs `L_p` normalization of inputs over specified dimension.

**Kind**: instance method of [`Tensor`](https://huggingface.co/docs/transformers.js/api/utils/tensor#module_utils/tensor.Tensor)\
**Returns**: `Tensor` - The normalized tensor.

| Param  | Type     | Default | Description                                |
| ------ | -------- | ------- | ------------------------------------------ |
| \[p]   | `number` | `2`     | The exponent value in the norm formulation |
| \[dim] | `number` | `1`     | The dimension to reduce                    |

***

#### tensor.stride() ⇒ \<code> Array. < number > \</code>

Compute and return the stride of this tensor. Stride is the jump necessary to go from one element to the next one in the specified dimension dim.

**Kind**: instance method of [`Tensor`](https://huggingface.co/docs/transformers.js/api/utils/tensor#module_utils/tensor.Tensor)\
**Returns**: `Array.<number>` - The stride of this tensor.

***

#### tensor.squeeze(\[dim]) ⇒

Returns a tensor with all specified dimensions of input of size 1 removed.

NOTE: The returned tensor shares the storage with the input tensor, so changing the contents of one will change the contents of the other. If you would like a copy, use `tensor.clone()` before squeezing.

**Kind**: instance method of [`Tensor`](https://huggingface.co/docs/transformers.js/api/utils/tensor#module_utils/tensor.Tensor)\
**Returns**: The squeezed tensor

| Param  | Type     | Default | Description                                                            |
| ------ | -------- | ------- | ---------------------------------------------------------------------- |
| \[dim] | `number` |         | If given, the input will be squeezed only in the specified dimensions. |

***

#### tensor.squeeze\_()

In-place version of @see [Tensor.squeeze](https://huggingface.co/docs/transformers.js/api/utils/Tensor.squeeze)

**Kind**: instance method of [`Tensor`](https://huggingface.co/docs/transformers.js/api/utils/tensor#module_utils/tensor.Tensor)

***

#### tensor.unsqueeze(dim) ⇒

Returns a new tensor with a dimension of size one inserted at the specified position.

NOTE: The returned tensor shares the same underlying data with this tensor.

**Kind**: instance method of [`Tensor`](https://huggingface.co/docs/transformers.js/api/utils/tensor#module_utils/tensor.Tensor)\
**Returns**: The unsqueezed tensor

| Param | Type     | Default | Description                                          |
| ----- | -------- | ------- | ---------------------------------------------------- |
| dim   | `number` |         | The index at which to insert the singleton dimension |

***

#### tensor.unsqueeze\_()

In-place version of @see [Tensor.unsqueeze](https://huggingface.co/docs/transformers.js/api/utils/Tensor.unsqueeze)

**Kind**: instance method of [`Tensor`](https://huggingface.co/docs/transformers.js/api/utils/tensor#module_utils/tensor.Tensor)

***

#### tensor.flatten\_()

In-place version of @see [Tensor.flatten](https://huggingface.co/docs/transformers.js/api/utils/Tensor.flatten)

**Kind**: instance method of [`Tensor`](https://huggingface.co/docs/transformers.js/api/utils/tensor#module_utils/tensor.Tensor)

***

#### tensor.flatten(start\_dim, end\_dim) ⇒

Flattens input by reshaping it into a one-dimensional tensor. If `start_dim` or `end_dim` are passed, only dimensions starting with `start_dim` and ending with `end_dim` are flattened. The order of elements in input is unchanged.

**Kind**: instance method of [`Tensor`](https://huggingface.co/docs/transformers.js/api/utils/tensor#module_utils/tensor.Tensor)\
**Returns**: The flattened tensor.

| Param      | Type     | Default | Description              |
| ---------- | -------- | ------- | ------------------------ |
| start\_dim | `number` | `0`     | the first dim to flatten |
| end\_dim   | `number` |         | the last dim to flatten  |

***

#### tensor.view(...dims) ⇒ \<code> Tensor \</code>

Returns a new tensor with the same data as the `self` tensor but of a different `shape`.

**Kind**: instance method of [`Tensor`](https://huggingface.co/docs/transformers.js/api/utils/tensor#module_utils/tensor.Tensor)\
**Returns**: `Tensor` - The tensor with the same data but different shape

| Param   | Type     | Description      |
| ------- | -------- | ---------------- |
| ...dims | `number` | the desired size |

***

### utils/tensor.transpose(tensor, axes) ⇒ \<code> Tensor \</code>

Transposes a tensor according to the provided axes.

**Kind**: static method of [`utils/tensor`](https://huggingface.co/docs/transformers.js/api/utils/tensor#module_utils/tensor)\
**Returns**: `Tensor` - The transposed tensor.

| Param  | Type    | Description                             |
| ------ | ------- | --------------------------------------- |
| tensor | `any`   | The input tensor to transpose.          |
| axes   | `Array` | The axes to transpose the tensor along. |

***

### utils/tensor.interpolate(input, size, mode, align\_corners) ⇒ \<code> Tensor \</code>

Interpolates an Tensor to the given size.

**Kind**: static method of [`utils/tensor`](https://huggingface.co/docs/transformers.js/api/utils/tensor#module_utils/tensor)\
**Returns**: `Tensor` - The interpolated tensor.

| Param          | Type             | Description                                                                    |
| -------------- | ---------------- | ------------------------------------------------------------------------------ |
| input          | `Tensor`         | The input tensor to interpolate. Data must be channel-first (i.e., \[c, h, w]) |
| size           | `Array.<number>` | The output size of the image                                                   |
| mode           | `string`         | The interpolation mode                                                         |
| align\_corners | `boolean`        | Whether to align corners.                                                      |

***

### utils/tensor.mean\_pooling(last\_hidden\_state, attention\_mask) ⇒ \<code> Tensor \</code>

Perform mean pooling of the last hidden state followed by a normalization step.

**Kind**: static method of [`utils/tensor`](https://huggingface.co/docs/transformers.js/api/utils/tensor#module_utils/tensor)\
**Returns**: `Tensor` - Returns a new Tensor of shape \[batchSize, embedDim].

| Param               | Type     | Description                                       |
| ------------------- | -------- | ------------------------------------------------- |
| last\_hidden\_state | `Tensor` | Tensor of shape \[batchSize, seqLength, embedDim] |
| attention\_mask     | `Tensor` | Tensor of shape \[batchSize, seqLength]           |

***

### utils/tensor.cat(tensors, dim) ⇒ \<code> Tensor \</code>

Concatenates an array of tensors along a specified dimension.

**Kind**: static method of [`utils/tensor`](https://huggingface.co/docs/transformers.js/api/utils/tensor#module_utils/tensor)\
**Returns**: `Tensor` - The concatenated tensor.

| Param   | Type             | Description                          |
| ------- | ---------------- | ------------------------------------ |
| tensors | `Array.<Tensor>` | The array of tensors to concatenate. |
| dim     | `number`         | The dimension to concatenate along.  |

***

### utils/tensor.stack(tensors, dim) ⇒ \<code> Tensor \</code>

Stack an array of tensors along a specified dimension.

**Kind**: static method of [`utils/tensor`](https://huggingface.co/docs/transformers.js/api/utils/tensor#module_utils/tensor)\
**Returns**: `Tensor` - The stacked tensor.

| Param   | Type             | Description                    |
| ------- | ---------------- | ------------------------------ |
| tensors | `Array.<Tensor>` | The array of tensors to stack. |
| dim     | `number`         | The dimension to stack along.  |

***

### utils/tensor.std\_mean(input, dim, correction, keepdim) ⇒ \<code> Array. < Tensor > \</code>

Calculates the standard deviation and mean over the dimensions specified by dim. dim can be a single dimension or `null` to reduce over all dimensions.

**Kind**: static method of [`utils/tensor`](https://huggingface.co/docs/transformers.js/api/utils/tensor#module_utils/tensor)\
**Returns**: `Array.<Tensor>` - A tuple of (std, mean) tensors.

| Param      | Type               | Description                                                                                                      |
| ---------- | ------------------ | ---------------------------------------------------------------------------------------------------------------- |
| input      | `Tensor`           | the input tenso                                                                                                  |
| dim        | `number` \| `null` | the dimension to reduce. If None, all dimensions are reduced.                                                    |
| correction | `number`           | difference between the sample size and sample degrees of freedom. Defaults to Bessel's correction, correction=1. |
| keepdim    | `boolean`          | whether the output tensor has dim retained or not.                                                               |

***

### utils/tensor.mean(input, dim, keepdim) ⇒

Returns the mean value of each row of the input tensor in the given dimension dim.

**Kind**: static method of [`utils/tensor`](https://huggingface.co/docs/transformers.js/api/utils/tensor#module_utils/tensor)\
**Returns**: A new tensor with means taken along the specified dimension.

| Param   | Type               | Description                                        |
| ------- | ------------------ | -------------------------------------------------- |
| input   | `Tensor`           | the input tensor.                                  |
| dim     | `number` \| `null` | the dimension to reduce.                           |
| keepdim | `boolean`          | whether the output tensor has dim retained or not. |

***

### utils/tensor.dynamicTimeWarping(matrix) ⇒ \<code> Array. < Array < number > > \</code>

Measures similarity between two temporal sequences (e.g., input audio and output tokens to generate token-level timestamps).

**Kind**: static method of [`utils/tensor`](https://huggingface.co/docs/transformers.js/api/utils/tensor#module_utils/tensor)

| Param  | Type     |
| ------ | -------- |
| matrix | `Tensor` |

***

### utils/tensor.ones(size)

Returns a tensor filled with the scalar value 1, with the shape defined by the variable argument size.

**Kind**: static method of [`utils/tensor`](https://huggingface.co/docs/transformers.js/api/utils/tensor#module_utils/tensor)

| Param | Type             | Description                                                     |
| ----- | ---------------- | --------------------------------------------------------------- |
| size  | `Array.<number>` | A sequence of integers defining the shape of the output tensor. |

***

### utils/tensor.ones\_like(tensor) ⇒

Returns a tensor filled with the scalar value 1, with the same size as input.

**Kind**: static method of [`utils/tensor`](https://huggingface.co/docs/transformers.js/api/utils/tensor#module_utils/tensor)\
**Returns**: The ones tensor.

| Param  | Type     | Description                                                 |
| ------ | -------- | ----------------------------------------------------------- |
| tensor | `Tensor` | The size of input will determine size of the output tensor. |

***

### utils/tensor\~ONNXTensor : \<code> Object \</code>

**Kind**: inner constant of [`utils/tensor`](https://huggingface.co/docs/transformers.js/api/utils/tensor#module_utils/tensor)

***

### utils/tensor\~reshape(data, dimensions) ⇒ \<code> \* \</code>

Reshapes a 1-dimensional array into an n-dimensional array, according to the provided dimensions.

**Kind**: inner method of [`utils/tensor`](https://huggingface.co/docs/transformers.js/api/utils/tensor#module_utils/tensor)\
**Returns**: `*` - The reshaped array.

| Param      | Type        | Description                  |
| ---------- | ----------- | ---------------------------- |
| data       | `Array.<T>` | The input array to reshape.  |
| dimensions | `DIM`       | The target shape/dimensions. |

**Example**

Copied

```
reshape([10                    ], [1      ]); // Type: number[]      Value: [10]
  reshape([1, 2, 3, 4            ], [2, 2   ]); // Type: number[][]    Value: [[1, 2], [3, 4]]
  reshape([1, 2, 3, 4, 5, 6, 7, 8], [2, 2, 2]); // Type: number[][][]  Value: [[[1, 2], [3, 4]], [[5, 6], [7, 8]]]
  reshape([1, 2, 3, 4, 5, 6, 7, 8], [4, 2   ]); // Type: number[][]    Value: [[1, 2], [3, 4], [5, 6], [7, 8]]
```

***

#### reshape\~reshapedArray : \<code> any \</code>

**Kind**: inner property of [`reshape`](https://huggingface.co/docs/transformers.js/api/utils/tensor#module_utils/tensor..reshape)

***

### utils/tensor\~DataArray : \<code> \* \</code>

**Kind**: inner typedef of [`utils/tensor`](https://huggingface.co/docs/transformers.js/api/utils/tensor#module_utils/tensor)

***

### utils/tensor\~NestArray : \<code> \* \</code>

This creates a nested array of a given type and depth (see examples).

**Kind**: inner typedef of [`utils/tensor`](https://huggingface.co/docs/transformers.js/api/utils/tensor#module_utils/tensor)\
**Example**

Copied

```
NestArray<string, 1>; // string[]
```

**Example**

Copied

```
NestArray<number, 2>; // number[][]
```

**Example**

Copied

```
NestArray<string, 3>; // string[][][] etc.
```
