Error: Runtime error: expected scalar type Float but found Double
w_true=torch.tensor([2,-3.4]).T
b_true=4.2
feature = torch.from_numpy(np.random.normal(0,1,(num_input,num_example)))
#feature = torch.float32(feature)
labels = torch.matmul(w_true.T,feature)+b_true
Problem: runtime error: expected scalar type float but found double
reason: NP random. The data generated by Rand() is float64, while torch defaults to float32, so the problem arises
solution
feature = torch.from_numpy(np.float32(np.random.normal(0,1,(num_input,num_example))))
Read More:
- [Solved] Pytorch Error: RuntimeError: expected scalar type Double but found Float
- Pytorch Error: runtimeerror: expected scalar type double but found float
- [Solved] RuntimeError: expected scalar type Long but found Float
- can‘t multiply sequence by non-int of type ‘numpy.float64‘
- How to Solve RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cpu
- Pytorch Error: RuntimeError: value cannot be converted to type float without overflow: (0.00655336,-0.00
- Tensor for argument #2 ‘mat1‘ is on CPU, but expected it to be on GPU (while checking arguments for
- 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
- To silence this warning, use `float` by itself. Doing this will not modify any behavior and is safe.
- [Solved] RuntimeError: scatter(): Expected dtype int64 for index
- Normalize error: TypeError: Input tensor should be a float tensor…
- [Solved] yolo Error: IndexError: invalid index to scalar variable.
- [How to Fix] TypeError: Cannot cast array data from dtype(‘float64‘) to dtype(‘<U32‘)….
- [Solved] RuntimeError: Input type (torch.FloatTensor) and weight type (torch.cuda.FloatTensor) should be the
- [Solved] torchsummary Error: RuntimeError: Input type (torch.cuda.FloatTensor) and weight type (torch.F
- Python errors: valueerror: if using all scalar values, you must pass an index (four solutions)
- [Solved] RuntimeError: cublas runtime error : resource allocation failed at
- [Solved] RuntimeError: gather(): Expected dtype int64 for index
- [Solved] RuntimeError: cuda runtime error: device-side assert trigger