TypeError: randint() received an invalid combination of arguments - got (int, int, int), but expecte

简介: TypeError: randint() received an invalid combination of arguments - got (int, int, int), but expecte

问题描述

使用torch.randint(0, 10, 10)创建张量时出现错误

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-72-cdd6eb2d3416> in <module>
----> 1 torch.randint(0,10,10)
TypeError: randint() received an invalid combination of arguments - got (int, int, int), but expected one of:
 * (int high, tuple of ints size, *, torch.Generator generator, Tensor out, torch.dtype dtype, torch.layout layout, torch.device device, bool requires_grad)
 * (int low, int high, tuple of ints size, *, torch.Generator generator, Tensor out, torch.dtype dtype, torch.layout layout, torch.device device, bool requires_grad)

原因分析:

函数的参数不对,torch.randint()一般需要三个参数分别是low、high、size。

我传入的是下面参数,出现错误

torch.randint(0, 10, 10)

解决方案:

将size维度用元组传入

torch.randint(0, 10, (10,))


目录
相关文章
|
9月前
error C2040: ‘n‘ : ‘int [1000]‘ differs in levels of indirection from ‘int ‘
error C2040: ‘n‘ : ‘int [1000]‘ differs in levels of indirection from ‘int ‘
82 0
|
4月前
|
Python
TypeError: int() argument must be a string, a bytes原因
Python开发过程中,使用int()函数来转换或生成int类型的数据时,如果Python抛出并提示TypeError: int() argument must be a string, a bytes-like object or a real number, not 'complex',那么原因在于传递给int()函数的参数类型有误,正如TypeError的提示,int()函数的参数必须是string字符串(数值字符串)、类似字节对象、real number数字等,而不可以是complex复数类型的数据。
108 0
|
10月前
|
SQL Java 数据库连接
attempted to return null from a method with a primitive return type
attempted to return null from a method with a primitive return type
93 0
|
10月前
|
关系型数据库 MySQL C++
Error:E0415 no suitable constructor exists to convert from “int“ to “Rational“
Error:E0415 no suitable constructor exists to convert from “int“ to “Rational“
120 0
TypeError: unsupported operand type(s) for -=: 'Retry' and 'int'
TypeError: unsupported operand type(s) for -=: 'Retry' and 'int'
351 0
TypeError: sequence item 0: expected string, int found
TypeError: sequence item 0: expected string, int found
关于 error: invalid types ‘int[int]‘ for array subscript 的解决
关于 error: invalid types ‘int[int]‘ for array subscript 的解决
1029 0
关于 error: invalid types ‘int[int]‘ for array subscript 的解决
成功解决ret = ret / rcountTypeError: unsupported operand type(s) for /: ‘str‘ and ‘int‘
成功解决ret = ret / rcountTypeError: unsupported operand type(s) for /: ‘str‘ and ‘int‘
成功解决ret = ret / rcountTypeError: unsupported operand type(s) for /: ‘str‘ and ‘int‘