Tensor division yields AssertionError

This is kind of a pytorch beginner question. In pytorch I’m trying to do element wise division with two tensors of size [5,5,3]. In numpy it works fine using np.divide(), but somehow I get an error here.

c = [torch.DoubleTensor of size 5x5x3]
input_patch = [torch.FloatTensor of size 5x5x3]

When executing:

torch.div(input_patch, c)

I get this error that I don’t understand.

line 317, in div
assert not torch.is_tensor(other)
AssertionError

Does it mean that variable c should not be a torch_tensor? After casting c to also be a FloatTensor gives the same error still.

Thank you!

any of these should work: torch.div, /.

In [1]: import torch

In [2]: a = torch.randn(3, 4)

In [3]: b = torch.randn(3, 4)

In [4]: c = torch.div(a, b)

In [5]: c = a / b

It’s weird that they dont. Can you print type(input_patch) and type(c) before running torch.div and see if there’s something amiss?

2 Likes

Hi thanks for the help. I’ve already found that the problem was that self.patch_filt was not defined as a Variable, so doing

Variable(torch.from_numpy(self.patch_filt[:, :, :, 0])).float()

solved the problem