Created
August 14, 2017 00:31
-
-
Save arunmallya/073d44d7e9a3bc925444d1e247c1e8da to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import print_function | |
import torch | |
A = torch.rand(4, 4) | |
An = A.numpy() | |
idx = torch.ByteTensor([1, 0, 0, 1]) | |
idxn = [True, False, False, True] | |
# Numpy indexing. | |
print('numpy') | |
print(An[idxn].shape) | |
print(An[:, idxn].shape) | |
# Torch indexing. | |
print('torch') | |
print(A[idx].size()) | |
print(A[:, idx].size()) | |
# Output. | |
""" | |
numpy | |
(2, 4) | |
(4, 2) | |
torch | |
Traceback (most recent call last): | |
File "bug.py", line 17, in <module> | |
print(A[idx].size()) | |
RuntimeError: inconsistent tensor size, expected src [4 x 4] and mask [4] to have the same number of elements, but got 16 and 4 elements respectively at /Users/soumith/miniconda2/conda-bld/pytorch_1501999754274/work/torch/lib/TH/generic/THTensorMath.c:197 | |
""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment