Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ce55cc9

Browse files
fix bug
1 parent 8894555 commit ce55cc9

1 file changed

Lines changed: 14 additions & 14 deletions

File tree

‎tutorial-contents-notebooks/201_torch_numpy.ipynb‎

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -183,14 +183,14 @@
183183
},
184184
{
185185
"cell_type": "code",
186-
"execution_count": 9,
186+
"execution_count": 2,
187187
"metadata": {},
188188
"outputs": [
189189
{
190190
"name": "stdout",
191191
"output_type": "stream",
192192
"text": [
193-
"\nmatrix multiplication (matmul) \nnumpy: [[ 7 10]\n [15 22]] \ntorch: tensor([[ 7., 10.],\n [15., 22.]])\n"
193+
"\nmatrix multiplication (matmul) \nnumpy: [[ 7 10]\n [15 22]] \ntorch: tensor([[ 7., 10.],\n [15., 22.]])\n"
194194
]
195195
}
196196
],
@@ -208,29 +208,29 @@
208208
},
209209
{
210210
"cell_type": "code",
211-
"execution_count": 14,
211+
"execution_count": 3,
212212
"metadata": {},
213213
"outputs": [
214214
{
215-
"name": "stdout",
216-
"output_type": "stream",
217-
"text": [
218-
"\n",
219-
"matrix multiplication (dot) \n",
220-
"numpy: [[ 7 10]\n",
221-
" [15 22]] \n",
222-
"torch: 30.0\n"
223-
]
215+
"ename": "RuntimeError",
216+
"evalue": "dot: Expected 1-D argument self, but got 2-D",
217+
"traceback": [
218+
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
219+
"\u001b[0;31mRuntimeError\u001b[0m Traceback (most recent call last)",
220+
"\u001b[0;32m<ipython-input-3-a29f9258176b>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0;34m'\\nmatrix multiplication (dot)'\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 6\u001b[0m \u001b[0;34m'\\nnumpy: '\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdata\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdot\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdata\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;31m# [[7, 10], [15, 22]]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 7\u001b[0;31m \u001b[0;34m'\\ntorch: '\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtorch\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdot\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtensor\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdot\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtensor\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;31m# 30.0. Beware that torch.dot does not broadcast, only works for 1-dimensional tensor\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 8\u001b[0m )\n",
221+
"\u001b[0;31mRuntimeError\u001b[0m: dot: Expected 1-D argument self, but got 2-D"
222+
],
223+
"output_type": "error"
224224
}
225225
],
226226
"source": [
227227
"# incorrect method\n",
228228
"data = np.array(data)\n",
229-
"tensor = torch.Tensor([1,2,3,4]\n",
229+
"tensor = torch.Tensor(data)\n",
230230
"print(\n",
231231
" '\\nmatrix multiplication (dot)',\n",
232232
" '\\nnumpy: ', data.dot(data), # [[7, 10], [15, 22]]\n",
233-
" '\\ntorch: ', torch.dot(tensor.dot(tensor) # 30.0. Beware that torch.dot does not broadcast, only works for 1-dimensional tensor\n",
233+
" '\\ntorch: ', torch.dot(tensor.dot(tensor)) # NOT WORKING! Beware that torch.dot does not broadcast, only works for 1-dimensional tensor\n",
234234
")"
235235
]
236236
},

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /