--
\\n\\n- \\n
- Home \\n
- HTML \\n
- JavaScript \\n
- CSS \\n
- Vue \\n
- React \\n
- Python3 \\n
- Java \\n
- C \\n
- C++ \\n
- C# \\n
- AI \\n
- Go \\n
- SQL \\n
- Linux \\n
- VS Code \\n
- Bootstrap \\n
- Git \\n
- Local Bookmarks \\n
- \\n
- Vue3 Tutorial \\n
- Vue2 Tutorial \\n
- \\n
- Bootstrap3 \\n
- Bootstrap4 \\n
- Bootstrap5 \\n
- \\n
- Machine Learning \\n
- PyTorch \\n
- TensorFlow \\n
- Sklearn \\n
- NLP \\n
- AI Agent \\n
- Ollama \\n
- Coding Plan \\n
PyTorch Tutorial
\\n\\n- \\n
- PyTorch Tutorial \\n
- PyTorch Introduction \\n
- PyTorch Install \\n
- PyTorch Convolutional Neural Network \\n
- PyTorch Recurrent Neural Network \\n
- Pytorch torch \\n
- PyTorch torch.nn \\n
- Transformer Models \\n
- PyTorch LSTM / GRU \\n
- PyTorch Word Embeddings \\n
- PyTorch Generative Adversarial Networks \\n
- PyTorch Autoencoders \\n
- PyTorch torchtext \\n
- PyTorch Mixed Precision Training \\n
- PyTorch TorchScript/ONNX Export \\n
-
PyTorch torch.nn Reference Manual\\n\\n
PyTorch torch.triu_indices functions
\\n\\n
\\n\\nPytorch torch Reference Manual
torch.triu_indicesis a function in PyTorch used to generate indices for the upper triangular matrix. It returns the row and column indices of the upper triangular part (including the diagonal).
\\n\\nFunction Definition
\\n\\ntorch.triu_indices(row, column, offset=0, dtype=torch.long, device='cpu')\\nParameter Description:
\\n\\n- \\n
row: Number of Rows \\n column: Number of Columns \\n offset: Diagonal Offset \\n dtype: Returned Data Type \\n device: Device \\n
\\n\\nUsage example
\\n\\nExamples
\\n\\nimport torch\\n\\n# Generate Upper Triangular Indices for 3x3 Matrix\\n\\n row, col = torch.triu_indices(3,3)\\n\\nprint("row:", row)\\n\\nprint("col:", col)\\nThe output result is:
\\n\\nrow: tensor([0, 0, 0, 1, 1, 2]) col: tensor([0, 1, 2, 1, 2, 2])
\\n\\nExample
import torch\\n\\n# Generate Indices and Use for Indexing Operations\\n\\n row, col = torch.triu_indices(3,3, offset=1)\\n\\n# Create 3x3 Matrix\\n\\n a = torch.ones(3,3)\\n\\n# Set Upper Triangular Part Using Indices\\n\\n a[row, col]=0\\n\\nprint(a)\\nThe output is:
\\n\\ntensor([[1., 1., 1.], [0., 1., 1.], [0., 0., 1.]])
\\n\\nExample
import torch\\n\\n# Non-square Matrix Case\\n\\n row, col = torch.triu_indices(3,4)\\n\\nprint("row:", row)\\n\\nprint("col:", col)\\nThe output is:
\\n\\nrow: tensor([0, 0, 0, 1, 1, 2]) col: tensor([0, 1, 2, 1, 2, 2])
\\n\\n
\\n\\n
\\n\\nPyTorch torch Reference Manual
AI is thinking...
\\n\\n\\n\\n\\n\\n
YouTip