Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert torch tensor to float?

I am using flask to do inference and I am getting this result. Is their any way to convert this tensor into float because I want to use this result to display in a react app:

{
  result: {
    predictions: "tensor([[-3.4333]], grad_fn=<AddmmBackward>)"
  }
}
like image 931
harsh Avatar asked Nov 15 '25 03:11

harsh


1 Answers

From Torch.Tensor.item docs:

x = torch.tensor([1.0])

print((x.item())

output:

1.0

type check:

print(type(x.item())

output:

float
like image 61
ImSo3K Avatar answered Nov 17 '25 19:11

ImSo3K



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!