
Last chance! 50% off unlimited learning
Sale ends in
Is_nonzero
torch_is_nonzero(self)
(Tensor) the input tensor.
Returns TRUE if the input
is a single element tensor which is not equal to zero
after type conversions.
i.e. not equal to torch_tensor(c(0))
or torch_tensor(c(0))
or
torch_tensor(c(FALSE))
.
Throws a RuntimeError
if torch_numel() != 1
(even in case
of sparse tensors).
if (torch_is_installed()) {
torch_is_nonzero(torch_tensor(c(0.)))
torch_is_nonzero(torch_tensor(c(1.5)))
torch_is_nonzero(torch_tensor(c(FALSE)))
torch_is_nonzero(torch_tensor(c(3)))
if (FALSE) {
torch_is_nonzero(torch_tensor(c(1, 3, 5)))
torch_is_nonzero(torch_tensor(c()))
}
}
Run the code above in your browser using DataLab