Skip to content

Commit

Permalink
easier to read tensor formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
rasbt committed Jun 3, 2024
1 parent 60f64bd commit f95e0a9
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions appendix-A/01_main-chapter-code/code-part1.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
Expand Down Expand Up @@ -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"
]
},
Expand Down Expand Up @@ -1336,7 +1340,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.4"
"version": "3.10.6"
}
},
"nbformat": 4,
Expand Down

0 comments on commit f95e0a9

Please sign in to comment.