Mix.install([
{:nx, "~> 0.7.3"}
])
tensors = [
Nx.tensor([1, 2, 3]),
Nx.tensor([4, 5, 6])
]
Nx.stack(tensors, axis: 0, name: :x)
#Nx.Tensor<
s64[x: 2][3]
[
[1, 2, 3],
[4, 5, 6]
]
>
Nx.stack(tensors, axis: 1, name: :x)
#Nx.Tensor<
s64[3][x: 2]
[
[1, 4],
[2, 5],
[3, 6]
]
>
tensors = [
Nx.tensor([[1, 2, 3]]),
Nx.tensor([[4, 5, 6]])
]
Nx.stack(tensors, axis: 0, name: :x)
#Nx.Tensor<
s64[x: 2][1][3]
[
[
[1, 2, 3]
],
[
[4, 5, 6]
]
]
>
Nx.stack(tensors, axis: 1, name: :x)
#Nx.Tensor<
s64[1][x: 2][3]
[
[
[1, 2, 3],
[4, 5, 6]
]
]
>
Nx.stack(tensors, axis: 2, name: :x)
#Nx.Tensor<
s64[1][3][x: 2]
[
[
[1, 4],
[2, 5],
[3, 6]
]
]
>
Nx.stack(tensors, axis: -1, name: :x)
#Nx.Tensor<
s64[1][3][x: 2]
[
[
[1, 4],
[2, 5],
[3, 6]
]
]
>
Nx.stack(tensors, axis: -2, name: :x)
#Nx.Tensor<
s64[1][x: 2][3]
[
[
[1, 2, 3],
[4, 5, 6]
]
]
>
Nx.stack(tensors, axis: -3, name: :x)
#Nx.Tensor<
s64[x: 2][1][3]
[
[
[1, 2, 3]
],
[
[4, 5, 6]
]
]
>