-
@@ -350,15 +315,15 @@
x <- torch_randn(4,4)
x[c(1,3), c(1,3)]
#> torch_tensor
-#> 1.0431 -0.1182
-#> 0.1822 -0.8745
+#> 1.3648 -1.3758
+#> 0.5429 -1.7990
#> [ CPUFloatType{2,2} ]
You can also use boolean vectors, for example:
x[c(TRUE, FALSE, TRUE, FALSE), c(TRUE, FALSE, TRUE, FALSE)]
#> torch_tensor
-#> 1.0431 -0.1182
-#> 0.1822 -0.8745
+#> 1.3648 -1.3758
+#> 0.5429 -1.7990
#> [ CPUFloatType{2,2} ]
The above examples also work if the index were long or boolean tensors, instead of R vectors. It’s also possible to index with multi-dimensional boolean tensors:
@@ -373,34 +338,27 @@
#> 6
#> [ CPUFloatType{3} ]