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,))


目录
相关文章
|
1月前
|
TensorFlow 算法框架/工具
Tensorflow error(二):x and y must have the same dtype, got tf.float32 != tf.int32
本文讨论了TensorFlow中的一个常见错误,即在计算过程中,变量的数据类型(dtype)不一致导致的错误,并通过使用`tf.cast`函数来解决这个问题。
20 0
|
4月前
|
开发者 Python
【Python】已解决:TypeError: a bytes-like object is required, not ‘int’
【Python】已解决:TypeError: a bytes-like object is required, not ‘int’
191 0
|
11月前
|
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复数类型的数据。
314 0
关于 error: invalid types ‘int[int]‘ for array subscript 的解决
关于 error: invalid types ‘int[int]‘ for array subscript 的解决
1386 0
关于 error: invalid types ‘int[int]‘ for array subscript 的解决
TypeError: unsupported operand type(s) for -=: 'Retry' and 'int'
TypeError: unsupported operand type(s) for -=: 'Retry' and 'int'
466 0
Python bug:ValueError: invalid literal for int() with base 10: ''
Python bug:ValueError: invalid literal for int() with base 10: ''
|
Python
【hacker的错误集】TypeError: can‘t multiply sequence by non-int of type ‘str‘
我比较喜欢通过单词的意思来分析报错 TypeError类型错误 multiply乘 sequence 序列 通过分析可以得出报错意思大概是类型错误:无法将序列与字符串类型的非整数相乘
365 0
【hacker的错误集】TypeError: can‘t multiply sequence by non-int of type ‘str‘
|
存储
TypeError: can only concatenate str (not “int“) to str
TypeError: can only concatenate str (not “int“) to str
380 0
TypeError: can only concatenate str (not “int“) to str
TypeError: sequence item 0: expected string, int found
TypeError: sequence item 0: expected string, int found

热门文章

最新文章