TUTORIALAI & dataFETCHED

PyTorch torch.randint_like 函数

PyTorch torch.randint_like 函数 Pytorch torch 参考手册 torch.randint_like 是 PyTorch 中用于创建与输入张量相同形状的整数随机张量的函数。 函数定义 torch.randint_like(input, low=0, high, dtype=None, device=None, requires_grad=False) 使用示例 实例 [mycode4..

Updated 7/16/2026

Tutorial detail pages default to noindex.

PyTorch torch.randint_like 函数


Pytorch torch 参考手册 Pytorch torch 参考手册

torch.randint_like 是 PyTorch 中用于创建与输入张量相同形状的整数随机张量的函数。

函数定义

torch.randint_like(input, low=0, high, dtype=None, device=None, requires_grad=False)

使用示例

实例

import torch

# 创建一个输入张量
input = torch.tensor([[1, 2], [3, 4]])

# 创建与输入相同形状的整数随机张量,范围 [0, 10)
x = torch.randint_like(input, 10)

print(x)

Pytorch torch 参考手册 Pytorch torch 参考手册