This commit is contained in:
morvanzhou
2018-08-06 19:24:48 +08:00
parent d053113d3a
commit 7d95eb3e30

View File

@ -37,16 +37,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"numpy array: [[0 1 2]\n",
" [3 4 5]] \n",
"torch tensor: \n",
" 0 1 2\n",
" 3 4 5\n",
"[torch.LongTensor of size 2x3]\n",
" \n",
"tensor to array: [[0 1 2]\n",
" [3 4 5]]\n"
"\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"
]
}
],
@ -71,16 +62,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"abs \n",
"numpy: [1 2 1 2] \n",
"torch: \n",
" 1\n",
" 2\n",
" 1\n",
" 2\n",
"[torch.FloatTensor of size 4]\n",
"\n"
"\nabs \nnumpy: [1 2 1 2] \ntorch: tensor([ 1., 2., 1., 2.])\n"
]
}
],
@ -103,12 +85,7 @@
{
"data": {
"text/plain": [
"\n",
" 1\n",
" 2\n",
" 1\n",
" 2\n",
"[torch.FloatTensor of size 4]"
"tensor([ 1., 2., 1., 2.])"
]
},
"execution_count": 4,
@ -129,16 +106,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"sin \n",
"numpy: [-0.84147098 -0.90929743 0.84147098 0.90929743] \n",
"torch: \n",
"-0.8415\n",
"-0.9093\n",
" 0.8415\n",
" 0.9093\n",
"[torch.FloatTensor of size 4]\n",
"\n"
"\nsin \nnumpy: [-0.84147098 -0.90929743 0.84147098 0.90929743] \ntorch: tensor([-0.8415, -0.9093, 0.8415, 0.9093])\n"
]
}
],
@ -159,12 +127,7 @@
{
"data": {
"text/plain": [
"\n",
" 0.2689\n",
" 0.1192\n",
" 0.7311\n",
" 0.8808\n",
"[torch.FloatTensor of size 4]"
"tensor([ 0.2689, 0.1192, 0.7311, 0.8808])"
]
},
"execution_count": 6,
@ -184,12 +147,7 @@
{
"data": {
"text/plain": [
"\n",
" 0.3679\n",
" 0.1353\n",
" 2.7183\n",
" 7.3891\n",
"[torch.FloatTensor of size 4]"
"tensor([ 0.3679, 0.1353, 2.7183, 7.3891])"
]
},
"execution_count": 7,
@ -210,10 +168,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"mean \n",
"numpy: 0.0 \n",
"torch: 0.0\n"
"\nmean \nnumpy: 0.0 \ntorch: tensor(0.)\n"
]
}
],
@ -235,15 +190,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"matrix multiplication (matmul) \n",
"numpy: [[ 7 10]\n",
" [15 22]] \n",
"torch: \n",
" 7 10\n",
" 15 22\n",
"[torch.FloatTensor of size 2x2]\n",
"\n"
"\nmatrix multiplication (matmul) \nnumpy: [[ 7 10]\n [15 22]] \ntorch: tensor([[ 7., 10.],\n [ 15., 22.]])\n"
]
}
],
@ -300,19 +247,16 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 10,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"\n",
" 7 10\n",
" 15 22\n",
"[torch.FloatTensor of size 2x2]"
"tensor([[ 7., 10.],\n [ 15., 22.]])"
]
},
"execution_count": 11,
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
@ -323,19 +267,16 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 11,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"\n",
" 1 4\n",
" 9 16\n",
"[torch.FloatTensor of size 2x2]"
"tensor([[ 1., 4.],\n [ 9., 16.]])"
]
},
"execution_count": 12,
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
@ -352,7 +293,7 @@
{
"data": {
"text/plain": [
"30.0"
"tensor(7.)"
]
},
"execution_count": 13,
@ -361,8 +302,7 @@
}
],
"source": [
"torch.dot(torch.Tensor([2, 3]), torch.Tensor([2, 1]))
7.0"
"torch.dot(torch.Tensor([2, 3]), torch.Tensor([2, 1]))"
]
},
{