本文簡要介紹python語言中 torch.bincount 的用法。
用法:
torch.bincount(input, weights=None, minlength=0) → Tensor一個形狀為
Size([max(input) + 1])的張量,如果input不為空,否則為Size(0)輸出(Tensor)
計算非負整數數組中每個值的頻率。
bin 的數量(大小 1)比
input中的最大值大一,除非input為空,在這種情況下,結果是大小為 0 的張量。如果指定了minlength,則 bin 的數量為至少minlength並且如果input為空,則結果是大小為minlength的張量用零填充。如果n是位置i的值,如果指定了weights則為out[n] += weights[i],否則為out[n] += 1。注意
當給定 CUDA 設備上的張量時,此操作可能會產生不確定的梯度。有關詳細信息,請參閱重現性。
例子:
>>> input = torch.randint(0, 8, (5,), dtype=torch.int64) >>> weights = torch.linspace(0, 1, steps=5) >>> input, weights (tensor([4, 3, 6, 3, 4]), tensor([ 0.0000, 0.2500, 0.5000, 0.7500, 1.0000]) >>> torch.bincount(input) tensor([0, 0, 0, 2, 2, 0, 1]) >>> input.bincount(weights) tensor([0.0000, 0.0000, 0.0000, 1.0000, 1.0000, 0.0000, 0.5000])
參數:
返回:
返回類型:
相關用法
- Python PyTorch binary_cross_entropy用法及代碼示例
- Python PyTorch binary_cross_entropy_with_logits用法及代碼示例
- Python PyTorch bitwise_right_shift用法及代碼示例
- Python PyTorch bitwise_and用法及代碼示例
- Python PyTorch bitwise_not用法及代碼示例
- Python PyTorch bitwise_xor用法及代碼示例
- Python PyTorch bitwise_or用法及代碼示例
- Python PyTorch bitwise_left_shift用法及代碼示例
- Python PyTorch bernoulli用法及代碼示例
- Python PyTorch backward用法及代碼示例
- Python PyTorch batched_powerSGD_hook用法及代碼示例
- Python PyTorch bleu_score用法及代碼示例
- Python PyTorch broadcast_tensors用法及代碼示例
- Python PyTorch build_vocab_from_iterator用法及代碼示例
- Python PyTorch broadcast_object_list用法及代碼示例
- Python PyTorch broadcast_shapes用法及代碼示例
- Python PyTorch bf16_compress_wrapper用法及代碼示例
- Python PyTorch bmm用法及代碼示例
- Python PyTorch baddbmm用法及代碼示例
- Python PyTorch broadcast_to用法及代碼示例
- Python PyTorch bf16_compress_hook用法及代碼示例
- Python PyTorch bucketize用法及代碼示例
- Python PyTorch block_diag用法及代碼示例
- Python PyTorch frexp用法及代碼示例
- Python PyTorch jvp用法及代碼示例
注:本文由純淨天空篩選整理自pytorch.org大神的英文原創作品 torch.bincount。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
