Create torch Tensor from R object
tensor_from_r(x, dtype = NULL, device = NULL, requires_grad = FALSE)
x | an R vector, matrix or array. |
---|---|
dtype | dtype |
device | device |
requires_grad | requires_grad |
it uses the R type when creating the tensor.
tensor_from_r(1:10)#> tensor #> 1 #> 2 #> 3 #> 4 #> 5 #> 6 #> 7 #> 8 #> 9 #> 10 #> [ Variable[CPUIntType]{10} ]#> tensor #> (1,.,.) = #> 0.0110 0.9199 #> 0.6219 0.9158 #> #> (2,.,.) = #> 0.7833 0.3254 #> 0.8661 0.0805 #> [ Variable[CPUFloatType]{2,2,2} ]#> tensor #> 1 0 1 0 #> 0 1 0 1 #> 1 0 1 0 #> [ Variable[CPUByteType]{3,4} ]