one_hot
¶
Creates one-hot encoded vectors for all elements provided in labels.
Given an array of labels [num_elements,], returns an array with shape [num_elements, num_classes]where each column is an all-zero vector with a one at the index of the label.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
labels
|
array
|
Array with the labels to transform to one-hot encoded vectors. |
required |
num_classes
|
Optional[int]
|
Number of labels for the one-hot encoding. By default,
|
None
|
Returns:
| Type | Description |
|---|---|
array
|
An array of shape [num_elements, num_classes] with one-hot encoded vectors. |
Source code in mlx_graphs/utils/array_ops.py
from mlx_graphs.utils.array_ops import one_hot · mlx_graphs/utils/array_ops.py