mirror of
https://github.com/rasbt/LLMs-from-scratch.git
synced 2025-10-20 04:20:13 +00:00
easier to read tensor formatting
This commit is contained in:
parent
60f64bdc23
commit
f95e0a910d
@ -137,13 +137,16 @@
|
|||||||
"tensor1d = torch.tensor([1, 2, 3])\n",
|
"tensor1d = torch.tensor([1, 2, 3])\n",
|
||||||
"\n",
|
"\n",
|
||||||
"# create a 2D tensor from a nested Python list\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",
|
"\n",
|
||||||
"# create a 3D tensor from a nested Python list\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",
|
"\n",
|
||||||
"# create a 3D tensor from NumPy array\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_2 = torch.tensor(ary3d) # Copies NumPy array\n",
|
||||||
"tensor3d_3 = torch.from_numpy(ary3d) # Shares memory with NumPy array"
|
"tensor3d_3 = torch.from_numpy(ary3d) # Shares memory with NumPy array"
|
||||||
]
|
]
|
||||||
@ -285,7 +288,8 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"source": [
|
"source": [
|
||||||
"tensor2d = torch.tensor([[1, 2, 3], [4, 5, 6]])\n",
|
"tensor2d = torch.tensor([[1, 2, 3], \n",
|
||||||
|
" [4, 5, 6]])\n",
|
||||||
"tensor2d"
|
"tensor2d"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@ -1336,7 +1340,7 @@
|
|||||||
"name": "python",
|
"name": "python",
|
||||||
"nbconvert_exporter": "python",
|
"nbconvert_exporter": "python",
|
||||||
"pygments_lexer": "ipython3",
|
"pygments_lexer": "ipython3",
|
||||||
"version": "3.11.4"
|
"version": "3.10.6"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"nbformat": 4,
|
"nbformat": 4,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user