This commit is contained in:
2025-06-12 00:14:11 +08:00
parent a647e99dc6
commit 8bf116cbde
2 changed files with 120 additions and 5 deletions

121
04.ipynb
View File

@ -2,16 +2,127 @@
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "initial_id",
"metadata": {
"collapsed": true
"collapsed": true,
"ExecuteTime": {
"end_time": "2025-06-11T15:26:24.930498Z",
"start_time": "2025-06-11T15:26:24.925343Z"
}
},
"outputs": [],
"source": [
"import torch\n",
"\n"
]
"import numpy as np\n",
"\n",
"torch.__version__"
],
"outputs": [
{
"data": {
"text/plain": [
"'2.2.1'"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"execution_count": 4
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2025-06-11T15:30:24.600025Z",
"start_time": "2025-06-11T15:30:24.594879Z"
}
},
"cell_type": "code",
"source": [
"a = torch.tensor(1)\n",
"b = a.item()\n",
"print(a)\n",
"print(b)"
],
"id": "ec73dc2f6feeece4",
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"tensor(1)\n",
"1\n"
]
}
],
"execution_count": 11
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2025-06-11T15:30:58.264992Z",
"start_time": "2025-06-11T15:30:58.260725Z"
}
},
"cell_type": "code",
"source": [
"a = [1, 2, 3]\n",
"b = torch.tensor(a)\n",
"c = b.numpy().tolist()\n",
"print(c)"
],
"id": "6c3e0063d8fcc299",
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[1, 2, 3]\n"
]
}
],
"execution_count": 13
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2025-06-11T15:33:27.945096Z",
"start_time": "2025-06-11T15:33:27.939574Z"
}
},
"cell_type": "code",
"source": [
"a = torch.zeros(2, 3, 5)\n",
"print(a.shape)\n",
"\n",
"print(a.size())\n",
"\n",
"print(a.numel())\n"
],
"id": "d04c60d3f01351c2",
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"torch.Size([2, 3, 5])\n",
"torch.Size([2, 3, 5])\n",
"30\n"
]
}
],
"execution_count": 18
},
{
"metadata": {},
"cell_type": "code",
"outputs": [],
"execution_count": null,
"source": [
"x = torch.rand(2, 3, 5)\n",
"print(x.shape)"
],
"id": "774add1439f9aa94"
}
],
"metadata": {