I’ve never worked with Torch, only tf/th…, but the workflow seemed very pleasant to me so I decided try to learn. I know that pytorch is a very new project but it would be neat if one writes a “pytorch for dummies”.

For instance, the fallowing code results in error:

(class model above)
self.affine1(10, 100)
(...)
x = np.random.random(10)
ipt = torch.from_numpy(x)
probs = model(Variable(ipt))

Then

TypeError: addmm_ received an invalid combination of arguments - got (int, int, torch.DoubleTensor, torch.FloatTensor), but expected one of:
* (torch.DoubleTensor mat1, torch.DoubleTensor mat2)
(...)

How is the proper data preparation in pytorch?

Thanks in advance and looking forward to use pytorch (the performance of the cart pole in openai gym was better than with other frameworks).

Obs: As I didn’t saw any other mechanic-ish question topic, nor a question flag, hope that is not off topic for the forum.

In this particular case, thanks for your feedback. We will improve our onboarding process, by making more newbie friendly tutorials.

In this case, x = np.random.random(10) returns a numpy ndarray of dtype=float64.
When you call ipt = torch.from_numpy(x), ipt is now a torch.DoubleTensor.

However, your model is expecting a torch.FloatTensor, so you simply do:

@gabrieldlm pytorch does not support broadcasting yet. You are trying to send ipt wich is a 1D vector of size 10 into a matrix-multiply, which expects a 2D Tensor.

You can do: ipt = ipt.view(1, 10) if it fits your usecase.

This is the first place I ended up in when searching the error: matrices expected, got 1D, 2D tensors at /py/conda-bld/pytorch_1490983232023/work/torch/lib/TH/generic/THTensorMath.c:1224

And even from smth’s comment and the documentation I’d say it’s not immediately obvious that the solution, at least in my case, is that the dimensionality of the input needed to be 3D rather than 2D. It does explain why .view() makes frequent appearances in some of the tutorials.