torch.hash_tensor#
- torch.hash_tensor(input, *, mode=0) Tensor#
返回
input張量中所有元素的雜湊值。目前只支援 mode=0(透過 xor 規約)。輸出將始終為
torch.uint64型別。在透過 xor 進行規約之前,input的元素將被提升為它們等效的 64 位浮點數/整數,並被位轉換為torch.uint64。示例
>>> a = torch.randn(1, 3) >>> a tensor([[ 1.1918, -1.1813, 0.3373]]) >>> torch.hash_tensor(a) tensor(13822780554648485888, dtype=torch.uint64)
- torch.hash_tensor(input, dim, *, keepdim=False, mode=0) Tensor
根據給定的
dim維度,返回input張量每一行的雜湊值(由 mode 指定)。如果dim是一個維度列表,則在所有這些維度上進行規約。如果
keepdim為True,則輸出張量的大小與input相同,只有在dim維度上大小為 1。否則,dim將被擠壓(參見torch.squeeze()),導致輸出張量維度減少 1(或len(dim))個。- 引數
- 關鍵字引數
mode (int) – 要使用的雜湊。預設值:0 (xor_reduction)
示例
>>> a = torch.randn(2, 4) >>> a tensor([[ 0.1317, -0.5554, -1.4724, -1.1391], [ 0.0778, -0.6070, 0.6375, 0.1798]]) >>> torch.hash_tensor(a, 1) tensor([9233691267014066176, 9255993250844508160], dtype=torch.uint64)