round() can round the zero or more values of a 0D or more D tensor up to 4 decimal places as shown below:
*Memos:
- round() can be used with torch or a tensor.
- The 1st argument(
tensor
ofint
orfloat
) withtorch
or using a tensor(tensor
ofint
orfloat
) isinput
(Required). - The 2nd argument(
int
) withtorch
or the 1st argument(int
) with a tensor isdecimals
(Optional-Default:0
) which is a decimal place. *You must usedecimals=
to set a decimal place. *You must usedecimals=
.
import torch
my_tensor = torch.tensor([4.735277, -3.370677, 1.888877, -7.888877])
torch.round(input=my_tensor)
my_tensor.round()
torch.round(input=my_tensor, decimals=0)
# tensor([5., -3., 2., -8.])
torch.round(input=my_tensor, decimals=1)
# tensor([4.7000, -3.4000, 1.9000, -7.9000])
torch.round(input=my_tensor, decimals=2)
# tensor([4.7400, -3.3700, 1.8900, -7.8900])
torch.round(input=my_tensor, decimals=3)
# tensor([4.7350, -3.3710, 1.8890, -7.8890])
torch.round(input=my_tensor, decimals=4)
torch.round(input=my_tensor, decimals=5)
torch.round(input=my_tensor, decimals=6)
etc...
# tensor([4.7353, -3.3707, 1.8889, -7.8889])
my_tensor = torch.tensor([4, -3, 1, -7])
torch.round(input=my_tensor)
# tensor([4, -3, 1, -7])
ceil() can round up the zero or more values of a 0D or more D tensor as shown below:
*Memos:
-
ceil()
can be used withtorch
or a tensor. - The 1st argument(
tensor
ofint
orfloat
) withtorch
or using a tensor(tensor
ofint
orfloat
) isinput
(Required). -
ceil()
doesn't havedecimals
argument.
import torch
my_tensor = torch.tensor([4.735277, -3.370677, 1.888877, -7.888877])
torch.ceil(input=my_tensor)
my_tensor.ceil()
# tensor([5., -3., 2., -7.])
my_tensor = torch.tensor([4, -3, 1, -7])
torch.ceil(input=my_tensor)
# tensor([4, -3, 1, -7])
floor() can round down the zero or more values of a 0D or more D tensor as shown below:
*Memos:
-
floor()
can be used withtorch
or a tensor. - The 1st argument(
tensor
ofint
orfloat
) withtorch
or using a tensor(tensor
ofint
orfloat
) isinput
(Required). -
floor()
doesn't havedecimals
argument.
import torch
my_tensor = torch.tensor([4.735277, -3.370677, 1.888877, -7.888877])
torch.floor(input=my_tensor)
my_tensor.floor()
# tensor([4., -4., 1., -8.])
my_tensor = torch.tensor([4, -3, 1, -7])
torch.floor(input=my_tensor)
# tensor([4, -3, 1, -7])
trunc() can truncate the decimal part of zero or more values of a 0D or more D tensor as shown below:
*Memos:
-
trunc()
can be used withtorch
or a tensor. - The 1st argument(
tensor
ofint
orfloat
) withtorch
or using a tensor(tensor
ofint
orfloat
) isinput
(Required). -
trunc()
doesn't havedecimals
argument. -
fix() is the alias of
trunc()
.
import torch
my_tensor = torch.tensor([4.735277, -3.370677, 1.888877, -7.888877])
torch.trunc(input=my_tensor)
my_tensor.trunc()
# tensor([4., -3., 1., -7.])
my_tensor = torch.tensor([4, -3, 1, -7])
torch.trunc(input=my_tensor)
# tensor([4, -3, 1, -7])
Top comments (0)