Skip to content

Commit 7d95eb3

Browse files
committed
update
1 parent d053113 commit 7d95eb3

1 file changed

Lines changed: 16 additions & 76 deletions

File tree

tutorial-contents-notebooks/201_torch_numpy.ipynb

Lines changed: 16 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,7 @@
3737
"name": "stdout",
3838
"output_type": "stream",
3939
"text": [
40-
"\n",
41-
"numpy array: [[0 1 2]\n",
42-
" [3 4 5]] \n",
43-
"torch tensor: \n",
44-
" 0 1 2\n",
45-
" 3 4 5\n",
46-
"[torch.LongTensor of size 2x3]\n",
47-
" \n",
48-
"tensor to array: [[0 1 2]\n",
49-
" [3 4 5]]\n"
40+
"\nnumpy array: [[0 1 2]\n [3 4 5]] \ntorch tensor: tensor([[ 0, 1, 2],\n [ 3, 4, 5]], dtype=torch.int32) \ntensor to array: [[0 1 2]\n [3 4 5]]\n"
5041
]
5142
}
5243
],
@@ -71,16 +62,7 @@
7162
"name": "stdout",
7263
"output_type": "stream",
7364
"text": [
74-
"\n",
75-
"abs \n",
76-
"numpy: [1 2 1 2] \n",
77-
"torch: \n",
78-
" 1\n",
79-
" 2\n",
80-
" 1\n",
81-
" 2\n",
82-
"[torch.FloatTensor of size 4]\n",
83-
"\n"
65+
"\nabs \nnumpy: [1 2 1 2] \ntorch: tensor([ 1., 2., 1., 2.])\n"
8466
]
8567
}
8668
],
@@ -103,12 +85,7 @@
10385
{
10486
"data": {
10587
"text/plain": [
106-
"\n",
107-
" 1\n",
108-
" 2\n",
109-
" 1\n",
110-
" 2\n",
111-
"[torch.FloatTensor of size 4]"
88+
"tensor([ 1., 2., 1., 2.])"
11289
]
11390
},
11491
"execution_count": 4,
@@ -129,16 +106,7 @@
129106
"name": "stdout",
130107
"output_type": "stream",
131108
"text": [
132-
"\n",
133-
"sin \n",
134-
"numpy: [-0.84147098 -0.90929743 0.84147098 0.90929743] \n",
135-
"torch: \n",
136-
"-0.8415\n",
137-
"-0.9093\n",
138-
" 0.8415\n",
139-
" 0.9093\n",
140-
"[torch.FloatTensor of size 4]\n",
141-
"\n"
109+
"\nsin \nnumpy: [-0.84147098 -0.90929743 0.84147098 0.90929743] \ntorch: tensor([-0.8415, -0.9093, 0.8415, 0.9093])\n"
142110
]
143111
}
144112
],
@@ -159,12 +127,7 @@
159127
{
160128
"data": {
161129
"text/plain": [
162-
"\n",
163-
" 0.2689\n",
164-
" 0.1192\n",
165-
" 0.7311\n",
166-
" 0.8808\n",
167-
"[torch.FloatTensor of size 4]"
130+
"tensor([ 0.2689, 0.1192, 0.7311, 0.8808])"
168131
]
169132
},
170133
"execution_count": 6,
@@ -184,12 +147,7 @@
184147
{
185148
"data": {
186149
"text/plain": [
187-
"\n",
188-
" 0.3679\n",
189-
" 0.1353\n",
190-
" 2.7183\n",
191-
" 7.3891\n",
192-
"[torch.FloatTensor of size 4]"
150+
"tensor([ 0.3679, 0.1353, 2.7183, 7.3891])"
193151
]
194152
},
195153
"execution_count": 7,
@@ -210,10 +168,7 @@
210168
"name": "stdout",
211169
"output_type": "stream",
212170
"text": [
213-
"\n",
214-
"mean \n",
215-
"numpy: 0.0 \n",
216-
"torch: 0.0\n"
171+
"\nmean \nnumpy: 0.0 \ntorch: tensor(0.)\n"
217172
]
218173
}
219174
],
@@ -235,15 +190,7 @@
235190
"name": "stdout",
236191
"output_type": "stream",
237192
"text": [
238-
"\n",
239-
"matrix multiplication (matmul) \n",
240-
"numpy: [[ 7 10]\n",
241-
" [15 22]] \n",
242-
"torch: \n",
243-
" 7 10\n",
244-
" 15 22\n",
245-
"[torch.FloatTensor of size 2x2]\n",
246-
"\n"
193+
"\nmatrix multiplication (matmul) \nnumpy: [[ 7 10]\n [15 22]] \ntorch: tensor([[ 7., 10.],\n [ 15., 22.]])\n"
247194
]
248195
}
249196
],
@@ -300,19 +247,16 @@
300247
},
301248
{
302249
"cell_type": "code",
303-
"execution_count": 11,
250+
"execution_count": 10,
304251
"metadata": {},
305252
"outputs": [
306253
{
307254
"data": {
308255
"text/plain": [
309-
"\n",
310-
" 7 10\n",
311-
" 15 22\n",
312-
"[torch.FloatTensor of size 2x2]"
256+
"tensor([[ 7., 10.],\n [ 15., 22.]])"
313257
]
314258
},
315-
"execution_count": 11,
259+
"execution_count": 10,
316260
"metadata": {},
317261
"output_type": "execute_result"
318262
}
@@ -323,19 +267,16 @@
323267
},
324268
{
325269
"cell_type": "code",
326-
"execution_count": 12,
270+
"execution_count": 11,
327271
"metadata": {},
328272
"outputs": [
329273
{
330274
"data": {
331275
"text/plain": [
332-
"\n",
333-
" 1 4\n",
334-
" 9 16\n",
335-
"[torch.FloatTensor of size 2x2]"
276+
"tensor([[ 1., 4.],\n [ 9., 16.]])"
336277
]
337278
},
338-
"execution_count": 12,
279+
"execution_count": 11,
339280
"metadata": {},
340281
"output_type": "execute_result"
341282
}
@@ -352,7 +293,7 @@
352293
{
353294
"data": {
354295
"text/plain": [
355-
"30.0"
296+
"tensor(7.)"
356297
]
357298
},
358299
"execution_count": 13,
@@ -361,8 +302,7 @@
361302
}
362303
],
363304
"source": [
364-
"torch.dot(torch.Tensor([2, 3]), torch.Tensor([2, 1]))
365-
7.0"
305+
"torch.dot(torch.Tensor([2, 3]), torch.Tensor([2, 1]))"
366306
]
367307
},
368308
{

0 commit comments

Comments
 (0)