# Why cannot the defined Variable be computed by nueral network?

**URL:** <https://discuss.pytorch.org/t/why-cannot-the-defined-variable-be-computed-by-nueral-network/67007>\
**Category:** deployment\
**Created:** [January 18, 2020, 12:41am UTC](https://discuss.pytorch.org/t/why-cannot-the-defined-variable-be-computed-by-nueral-network/67007 "2020-01-18T00:41:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![999999999](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/999999999/32/43009_2.png) [@999999999](https://discuss.pytorch.org/u/999999999)\
**Post date:** [January 18, 2020, 12:41am UTC](https://discuss.pytorch.org/t/why-cannot-the-defined-variable-be-computed-by-nueral-network/67007/1 "2020-01-18T00:41:18Z")

</div>

**the neural network is defined as**  
class networka(nn.Module):  
def **init** (self):  
super(networka,self). **init** ()  
self.network=nn.Sequential(  
nn.Linear(19,11),  
nn.ReLU(True),  
nn.Linear(11,3),  
nn.Softmax()  
)  
def forward(self, x):  
x=self.network(x)  
return x  
A=networka()

**This code works**

z = Variable(torch.randn(19,19))  
A(z)

**But this doesn’t**

X\_data=(np.random.rand(19,19))  
X=Variable(torch.from\_numpy(X\_data))  
A(X)

Could anyone tell me why?

---

<div class="post-metadata">

**Author:** ![ptrblck](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/ptrblck/32/1823_2.png) [@ptrblck](https://discuss.pytorch.org/u/ptrblck)\
**Post date:** [January 19, 2020, 9:48am UTC](https://discuss.pytorch.org/t/why-cannot-the-defined-variable-be-computed-by-nueral-network/67007/2 "2020-01-19T09:48:27Z")

</div>

You should get an error message:

```python
RuntimeError: Expected object of scalar type Float but got scalar type Double for argument #2 'mat1' in call to _th_addmm

```

which points to a type mismatch in an operation.

Numpy uses float64 by default, while PyTorch uses float32.  
You could either transform the data to float32 via `X = X.float()`, which would be the usual use case or alternatively you could transform the model parameters to float64 via `model = model.double`.

Also, `Variables` are deprecated since PyTorch `0.4.0`, so don’t use them.

---

<div class="post-metadata">

**Author:** ![999999999](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/999999999/32/43009_2.png) [@999999999](https://discuss.pytorch.org/u/999999999)\
**Post date:** [January 19, 2020, 4:33pm UTC](https://discuss.pytorch.org/t/why-cannot-the-defined-variable-be-computed-by-nueral-network/67007/3 "2020-01-19T16:33:35Z")

</div>

Thank you very much for your help!

ptrblck via PyTorch Forums [noreply@discuss.pytorch.org](mailto:noreply@discuss.pytorch.org)于2020年1月19日 周日01:58写道：
