Newbie question: what is the corresponding method of mat[:, 1, :]
with mat
as a 3-D matrix in pyTorch?
#1845
-
I looked over https://docs.rs/burn/latest/burn/prelude/struct.Tensor.html, and did not find a way to directly do this. |
Beta Was this translation helpful? Give feedback.
Answered by
nathanielsimard
Jun 5, 2024
Replies: 1 comment 1 reply
-
I think it's a simple let [d1, d2, d3] = mat.shape();
// to read the matrix, like `x = mat[:, 1, :]`
let x = mat.slice(0..d1, 0..1, 0..d3);
// to write to the matrix, like `mat[:, 1, :] = value` but it returns the results instead of mutating the tensor inplace.
let x = mat.slice_assign(0..d1, 0..1, 0..d3, value); |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
Magicloud
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think it's a simple
slice
orslice_assign
method call that you need. When using this function you need to specify the range included in every dimension: