Row 5407
Content Data
This page contains data entry 5407 from the Axioma AXP content repository. The structured data below represents the complete record for this entry.
I have the following input matrix
inp_tensor = torch.tensor( [[0.7860, 0.1115, 0.0000, 0.6524, 0.6057, 0.3725, 0.7980, 0.0000], [1.0000, 0.1115, 0.0000, 0.6524, 0.6057, 0.3725, 0.0000, 1.0000]])
and indices of the zero elements
mask_indices = torch.tensor( [[7, 2], [2, 6]])
How can I exclude the nonzero elements from the multiplication with the following matrix:
my_tensor = torch.tensor( [[0.8823, 0.9150, 0.3829], [0.9593, 0.3904, 0.6009], [0.2566, 0.7936, 0.9408], [0.1332, 0.9346, 0.5936], [0.8694, 0.5677, 0.7411], [0.4294, 0.8854, 0.5739], [0.2666, 0.6274, 0.2696], [0.4414, 0.2969, 0.8317]])
That is, instead of multiplying it including the zeros:
a = torch.mm(inp_tensor, my_tensor) print(a) tensor([[1.7866, 2.5468, 1.6330], [2.2041, 2.5388, 2.3315]])
I want to exclude the zero elements (and the corresponding rows of my\_tensor):
inp_tensor = torch.tensor( [[0.7860, 0.1115, 0.6524, 0.6057, 0.3725, 0.7980]]) # remove the zero elements my_tensor = torch.tensor( [[0.8823, 0.9150, 0.3829], [0.9593, 0.3904, 0.6009], [0.1332, 0.9346, 0.5936], [0.8694, 0.5677, 0.7411], [0.4294, 0.8854, 0.5739], [0.2666, 0.6274, 0.2696]]) # remove the corresponding zero elements rows b = torch.mm(inp_tensor, my_tensor) print(b) >>> tensor([[1.7866, 2.5468, 1.6330]]) inp_tensor = torch.tensor([[1.0000, 0.1115, 0.6524, 0.6057, 0.3725, 1.0000]]) # remove the zero elements my_tensor = torch.tensor( [ [0.8823, 0.9150, 0.3829], [0.9593, 0.3904, 0.6009], [0.1332, 0.9346, 0.5936], [0.8694, 0.5677, 0.7411], [0.4294, 0.8854, 0.5739], [0.4414, 0.2969, 0.8317]]) # remove the corresponding zero elements rows c = torch.mm(inp_tensor, my_tensor) print(c) >>> tensor([[2.2041, 2.5388, 2.3315]]) print(torch.cat([b,c])) >>> tensor([[1.7866, 2.5468, 1.6330], [2.2041, 2.5388, 2.3315]])
I need this to be efficient (i.e., no for loops), as my tensors are quite large, and also to maintain the gradient (i.e., if I call optimizer.backward() that the relevant parameters from the computational graph be updated)
| Field | Value |
|---|---|
| text | I have the following input matrix inp_tensor = torch.tensor( [[0.7860, 0.1115, 0.0000, 0.6524, 0.6057, 0.3725, 0.7980, 0.0000], [1.0000, 0.1115, 0.0000, 0.6524, 0.6057, 0.3725, 0.0000, 1.0000]]) and indices of the zero elements mask_indices = torch.tensor( [[7, 2], [2, 6]]) How can I exclude the nonzero elements from the multiplication with the following matrix: my_tensor = torch.tensor( [[0.8823, 0.9150, 0.3829], [0.9593, … |
| label | r/pytorch |
| dataType | post |
| communityName | r/pytorch |
| datetime | 2024-04-29 |
| username_encoded | Z0FBQUFBQm5LakwyTnBac3pDZDdBZXFoWDNOWmRJbjczU3ZwWmp3WmtnOXk0Q2J2YUlBNE1WVmtqQjhiZHkzVkhPWDhUb3ZzTnNEOHVvOWEyTE40NUFRcjFjd0tnNHlac3c9PQ== |
| url_encoded | Z0FBQUFBQm5Lak9GQTN3Y3duOTgybTVNWkZDSjdYaXhsMVBJUkNJUlR3QjBPZkxXOGhWSExULWFFRGNoV0tyTGUyUXp4VXlPc0wzVUUxWUJ4MEtpU0g4NGt4ZmVkNnkwM0J0VGRLUElNNmdXc0g1YkJpdnBrLXMxT1YzSTlOQ1RDcFZnaGM5Wk4wYXJHTFpkNVRoOFdnNHJyWU9uc1NKWnh4c1RsWGVsXzZaRjllZ2p0UnFrMndtZFhCRmhaTGZ0SmEyYWZLd3ZIRUM0VFNrYnBEckctR21jZndLc1VydXMwUT09 |
Raw Record
{
"text": "I have the following input matrix\n\n inp_tensor = torch.tensor(\n [[0.7860, 0.1115, 0.0000, 0.6524, 0.6057, 0.3725, 0.7980, 0.0000],\n [1.0000, 0.1115, 0.0000, 0.6524, 0.6057, 0.3725, 0.0000, 1.0000]])\n\nand indices of the zero elements\n\n mask_indices = torch.tensor(\n [[7, 2],\n [2, 6]])\n\nHow can I exclude the nonzero elements from the multiplication with the following matrix:\n\n my_tensor = torch.tensor(\n [[0.8823, 0.9150, 0.3829],\n [0.9593, 0.3904, 0.6009],\n [0.2566, 0.7936, 0.9408],\n [0.1332, 0.9346, 0.5936],\n [0.8694, 0.5677, 0.7411],\n [0.4294, 0.8854, 0.5739],\n [0.2666, 0.6274, 0.2696],\n [0.4414, 0.2969, 0.8317]])\n\nThat is, instead of multiplying it including the zeros:\n\n a = torch.mm(inp_tensor, my_tensor)\n print(a)\n tensor([[1.7866, 2.5468, 1.6330],\n [2.2041, 2.5388, 2.3315]])\n\nI want to exclude the zero elements (and the corresponding rows of my\\_tensor):\n\n inp_tensor = torch.tensor(\n [[0.7860, 0.1115, 0.6524, 0.6057, 0.3725, 0.7980]]) # remove the zero elements\n \n my_tensor = torch.tensor(\n [[0.8823, 0.9150, 0.3829],\n [0.9593, 0.3904, 0.6009],\n [0.1332, 0.9346, 0.5936],\n [0.8694, 0.5677, 0.7411],\n [0.4294, 0.8854, 0.5739],\n [0.2666, 0.6274, 0.2696]]) # remove the corresponding zero elements rows\n \n b = torch.mm(inp_tensor, my_tensor)\n print(b)\n >>> tensor([[1.7866, 2.5468, 1.6330]])\n \n inp_tensor = torch.tensor([[1.0000, 0.1115, 0.6524, 0.6057, 0.3725, 1.0000]]) # remove the zero elements\n \n my_tensor = torch.tensor(\n [\n [0.8823, 0.9150, 0.3829], \n [0.9593, 0.3904, 0.6009],\n [0.1332, 0.9346, 0.5936],\n [0.8694, 0.5677, 0.7411],\n [0.4294, 0.8854, 0.5739],\n [0.4414, 0.2969, 0.8317]]) # remove the corresponding zero elements rows\n \n c = torch.mm(inp_tensor, my_tensor)\n print(c)\n >>> tensor([[2.2041, 2.5388, 2.3315]])\n print(torch.cat([b,c]))\n >>> tensor([[1.7866, 2.5468, 1.6330],\n [2.2041, 2.5388, 2.3315]])\n\nI need this to be efficient (i.e., no for loops), as my tensors are quite large, and also to maintain the gradient (i.e., if I call optimizer.backward() that the relevant parameters from the computational graph be updated)",
"label": "r/pytorch",
"dataType": "post",
"communityName": "r/pytorch",
"datetime": "2024-04-29",
"username_encoded": "Z0FBQUFBQm5LakwyTnBac3pDZDdBZXFoWDNOWmRJbjczU3ZwWmp3WmtnOXk0Q2J2YUlBNE1WVmtqQjhiZHkzVkhPWDhUb3ZzTnNEOHVvOWEyTE40NUFRcjFjd0tnNHlac3c9PQ==",
"url_encoded": "Z0FBQUFBQm5Lak9GQTN3Y3duOTgybTVNWkZDSjdYaXhsMVBJUkNJUlR3QjBPZkxXOGhWSExULWFFRGNoV0tyTGUyUXp4VXlPc0wzVUUxWUJ4MEtpU0g4NGt4ZmVkNnkwM0J0VGRLUElNNmdXc0g1YkJpdnBrLXMxT1YzSTlOQ1RDcFZnaGM5Wk4wYXJHTFpkNVRoOFdnNHJyWU9uc1NKWnh4c1RsWGVsXzZaRjllZ2p0UnFrMndtZFhCRmhaTGZ0SmEyYWZLd3ZIRUM0VFNrYnBEckctR21jZndLc1VydXMwUT09"
}
Entry Information
- Entry ID: 5407
- Repository: Axioma AXP
- Dataset: arrmlet/reddit_dataset_36
- Total Entries: 100,000