- edited description
Indexing: Selecting columns with booleans
Issue #55
new
Something goes wrong, indexing a 2D array with an array of booleans to select columns. Instead of selecting the columns, the rows are selected and reshaped.
Simple minimal example, hopefully clarifying what I mean:
>>>> x = np.array([[i + 2*j for j in range(10)]for i in range(10)])
>>>> b = np.array([True,False] * 5)
>>>> x
array([[ 0, 2, 4, 6, 8, 10, 12, 14, 16, 18],
[ 1, 3, 5, 7, 9, 11, 13, 15, 17, 19],
[ 2, 4, 6, 8, 10, 12, 14, 16, 18, 20],
[ 3, 5, 7, 9, 11, 13, 15, 17, 19, 21],
[ 4, 6, 8, 10, 12, 14, 16, 18, 20, 22],
[ 5, 7, 9, 11, 13, 15, 17, 19, 21, 23],
[ 6, 8, 10, 12, 14, 16, 18, 20, 22, 24],
[ 7, 9, 11, 13, 15, 17, 19, 21, 23, 25],
[ 8, 10, 12, 14, 16, 18, 20, 22, 24, 26],
[ 9, 11, 13, 15, 17, 19, 21, 23, 25, 27]])
>>>> b
array([ True, False, True, False, True, False, True, False, True, False], dtype=bool)
>>>> x[b,:]
array([[ 0, 2, 4, 6, 8, 10, 12, 14, 16, 18],
[ 2, 4, 6, 8, 10, 12, 14, 16, 18, 20],
[ 4, 6, 8, 10, 12, 14, 16, 18, 20, 22],
[ 6, 8, 10, 12, 14, 16, 18, 20, 22, 24],
[ 8, 10, 12, 14, 16, 18, 20, 22, 24, 26]])
>>>> x[:,b]
array([[ 0, 2, 4, 6, 8],
[10, 12, 14, 16, 18],
[ 2, 4, 6, 8, 10],
[12, 14, 16, 18, 20],
[ 4, 6, 8, 10, 12],
[14, 16, 18, 20, 22],
[ 6, 8, 10, 12, 14],
[16, 18, 20, 22, 24],
[ 8, 10, 12, 14, 16],
[18, 20, 22, 24, 26]])
EDIT
pypy version details:
$ pypy2-v5.4.1-linux64/bin/pypy
Python 2.7.10 (c95650101a99, Sep 06 2016, 11:10:29)
[PyPy 5.4.1 with GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>>
Comments (2)
-
reporter -
reporter - edited description
- Log in to comment