Add / substract between matrix and vector in pytorch
Add / substract between matrix and vector in pytorch I want to do + / - / * between matrix and vector in pytorch. How can I do with good performance? I tried to use expand, but it's really slow (I am using big matrix with small vector). a = torch.rand(2,3) print(a) 0.7420 0.2990 0.3896 0.0715 0.6719 0.0602 [torch.FloatTensor of size 2x3] b = torch.rand(2) print(b) 0.3773 0.6757 [torch.FloatTensor of size 2] a.add(b) Traceback (most recent call last): File "C:ProgramDataAnaconda3libsite-packagesIPythoncoreinteractiveshell.py", line 3066, in run_code exec(code_obj, self.user_global_ns, self.user_ns) File "<ipython-input-17-a1cb1b03d031>", line 1, in <module> a.add(b) RuntimeError: inconsistent tensor size, expected r_ [2 x 3], t [2 x 3] and src [2] to have the same number of elements, but got 6, 6 and 2 elements respectively at c:miniconda2conda-bldpytorch-cpu_1519449358620worktorchlibthgeneric/THTensorMath.c:1021 Expected result: ...
