easier to read tensor formatting

This commit is contained in:
rasbt 2024-06-02 20:41:34 -05:00
parent 60f64bdc23
commit f95e0a910d
No known key found for this signature in database
GPG Key ID: 3C6E5C7C075611DB

View File

@ -137,13 +137,16 @@
"tensor1d = torch.tensor([1, 2, 3])\n",
"\n",
"# create a 2D tensor from a nested Python list\n",
"tensor2d = torch.tensor([[1, 2], [3, 4]])\n",
"tensor2d = torch.tensor([[1, 2], \n",
" [3, 4]])\n",
"\n",
"# create a 3D tensor from a nested Python list\n",
"tensor3d_1 = torch.tensor([[[1, 2], [3, 4]], [[5, 6], [7, 8]]])\n",
"tensor3d_1 = torch.tensor([[[1, 2], [3, 4]], \n",
" [[5, 6], [7, 8]]])\n",
"\n",
"# create a 3D tensor from NumPy array\n",
"ary3d = np.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]]])\n",
"ary3d = np.array([[[1, 2], [3, 4]], \n",
" [[5, 6], [7, 8]]])\n",
"tensor3d_2 = torch.tensor(ary3d) # Copies NumPy array\n",
"tensor3d_3 = torch.from_numpy(ary3d) # Shares memory with NumPy array"
]
@ -285,7 +288,8 @@
}
],
"source": [
"tensor2d = torch.tensor([[1, 2, 3], [4, 5, 6]])\n",
"tensor2d = torch.tensor([[1, 2, 3], \n",
" [4, 5, 6]])\n",
"tensor2d"
]
},
@ -1336,7 +1340,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.4"
"version": "3.10.6"
}
},
"nbformat": 4,