Pytorch tensor Tensors operations

Pytorch tensor Tensors operations

Determine whether obj is a pytorch tensor

torch.is_tensor
torch.is_tensor(obj)

Determine whether obj is a pytorch storage object

torch.is_storage
torch.is_storage(obj)

Query the number of elements in a tensor:

torch.numel( obj) -> int
Example:
a = torch.randn(1, 2, 3, 4, 5)
torch.numel(a) -> 120
a = torch.zeros(4, 4)
torch.numel(a) -> 16

Set printing options

torch.set_printoptions(precision=None,  threshold=None, edgeitems=None, linewidth=None, profile=None)

parameter:

  • precision - Number of digits of precision for floating point output (default 8 digits)
  • threshold - threshold, the total number of array elements that trigger summary display instead of full display (repr) (default is 1000)
  • edgeitems - the number of items displayed at both ends of each dimension in the summary display (default value is 3)
  • linewidth - Number of characters per line used to insert line gaps (default is 80)
  • profile - prints the full defaults. All options above can be overridden

Guess you like

Origin blog.csdn.net/weixin_43915090/article/details/134759001