150 lines
2.7 KiB
Plaintext
150 lines
2.7 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "code",
|
|
"id": "initial_id",
|
|
"metadata": {
|
|
"collapsed": true,
|
|
"ExecuteTime": {
|
|
"end_time": "2025-06-11T15:26:24.930498Z",
|
|
"start_time": "2025-06-11T15:26:24.925343Z"
|
|
}
|
|
},
|
|
"source": [
|
|
"import torch\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": {
|
|
"kernelspec": {
|
|
"display_name": "Python 3",
|
|
"language": "python",
|
|
"name": "python3"
|
|
},
|
|
"language_info": {
|
|
"codemirror_mode": {
|
|
"name": "ipython",
|
|
"version": 2
|
|
},
|
|
"file_extension": ".py",
|
|
"mimetype": "text/x-python",
|
|
"name": "python",
|
|
"nbconvert_exporter": "python",
|
|
"pygments_lexer": "ipython2",
|
|
"version": "2.7.6"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 5
|
|
}
|