Skip to content

Commit 647a515

Browse files
authored
Merge pull request #17 from okdolly/patch-1
torch.dot does not broadcast
2 parents 0b09c05 + b048c4d commit 647a515

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

tutorial-contents-notebooks/201_torch_numpy.ipynb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,10 +279,11 @@
279279
"source": [
280280
"# incorrect method\n",
281281
"data = np.array(data)\n",
282+
"tensor = torch.Tensor([1,2,3,4]\n",
282283
"print(\n",
283284
" '\\nmatrix multiplication (dot)',\n",
284285
" '\\nnumpy: ', data.dot(data), # [[7, 10], [15, 22]]\n",
285-
" '\\ntorch: ', tensor.dot(tensor) # this will convert tensor to [1,2,3,4], you'll get 30.0\n",
286+
" '\\ntorch: ', torch.dot(tensor.dot(tensor) # 30.0. Beware that torch.dot does not broadcast, only works for 1-dimensional tensor\n",
286287
")"
287288
]
288289
},
@@ -360,7 +361,8 @@
360361
}
361362
],
362363
"source": [
363-
"tensor.dot(tensor)"
364+
"torch.dot(torch.Tensor([2, 3]), torch.Tensor([2, 1]))
365+
7.0"
364366
]
365367
},
366368
{

0 commit comments

Comments
 (0)