RuntimeError: scatter(): Expected dtype int64 for index
1. Error reporting reason:
Scatter requires the data to be of type Int64, and I wrote torch when defining tensor Tensor (x) should be written as torch Longtensor (x), specified as Int64 type.
2. Solutions
Find the definition method of the original data and change it
generally, dtype = NP int64; dtype=np.
in float32 (most definition functions have dtype attribute)
it is better to have the same number of bits of int and float
import numpy as np
a = np.random.randint(100, size=(10**6), dtype="int64")
print(a)
print(type(a[0]))
Read More:
- [Solved] RuntimeError: gather(): Expected dtype int64 for index
- dtype=np.int error: DeprecationWarning: `np.int` is a deprecated alias for the builtin `int`.
- [How to Fix] TypeError: Cannot cast array data from dtype(‘float64‘) to dtype(‘<U32‘)….
- [Solved] ufunc ‘add‘ did not contain a loop with signature matching types (dtype(‘<U32‘), dtype(‘<U32‘))
- [Solved] Pytorch Error: RuntimeError: expected scalar type Double but found Float
- [Solved] RuntimeError: expected scalar type Long but found Float
- Python PIP TypeError: expected str, bytes or os.PathLike object, not int
- [Solved] pytorch loss.backward() Error: RuntimeError: Function AddBackward0 returned an invalid gradient at index 1…
- Pytorch Error: runtimeerror: expected scalar type double but found float
- [Solved] RuntimeError: unexpected EOF, expected 73963 more bytes. The file might be corrupted.
- Python RuntimeError: Expected 4-dimensional input for 4-dimensional weight [32, 1, 5, 5]
- [Solved] Matplotlib scatter Draw Error: TypeError: ufunc ‘sqrt‘ not supported for the input types…rule ‘‘safe‘‘
- How to Solve RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cpu
- Python scatter chart error: TypeError: object of type ‘NoneType’ has no len()
- [Solved] Runtime error: expected scalar type Float but found Double
- ValueError: Found array with dim 4. Estimator expected and ValueError: Expected 2D array, got 1D array i
- Autograd error in Python: runtimeerror: grad can be implicitly created only for scalar outputs
- [How to Solve] Python TypeError: ‘int‘ object is not subscriptable
- [Solved] RuntimeError: Numpy is not available (Associated Torch or Tensorflow)
- [Solved] TypeError: unsupported operand type(s) for /: ‘str‘ and ‘int‘