scatter_softmax
¶
Computes the softmax of values that are scattered along a specified axis, grouped by index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
array
|
Input array containing values to be scattered. These values will undergo a scatter and softmax operation |
required |
index
|
array
|
Array containing indices that determine the scatter of the 'values'. |
required |
out_size
|
int
|
Size of the output array |
required |
axis
|
int
|
Axis along which to scatter |
0
|
Returns:
| Type | Description |
|---|---|
array
|
The resulting array after applying scatter and softmax operations on the |
array
|
input 'values'. |
Example:
src = mx.array([1., 1., 1., 1.])
index = mx.array([0, 0, 1, 2])
num_nodes = src.shape[0]
scatter_softmax(src, index, num_nodes)
>>> mx.array([0.5, 0.5, 1, 1])
Source code in mlx_graphs/utils/scatter.py
from mlx_graphs.utils.scatter import scatter_softmax · mlx_graphs/utils/scatter.py