diff options
author | mlai <mlai@begws92.beg.utexas.edu> | 2015-07-11 12:05:14 -0500 |
---|---|---|
committer | mlai <mlai@begws92.beg.utexas.edu> | 2015-07-11 14:06:00 -0500 |
commit | 2be00c3fe6f6d84d4449b1cb26452642b48c0661 (patch) | |
tree | 6d62ae895b02391bb11949e1a765a2f002182fb3 /numpy/lib | |
parent | 0c97cdeb1b29776f927fea4830c802e0339ac8dd (diff) | |
download | numpy-2be00c3fe6f6d84d4449b1cb26452642b48c0661.tar.gz |
BUG: made view of new array to fix ix_ bug
closes gh-6062
done with help of Sebastian Berg! =)
Diffstat (limited to 'numpy/lib')
-rw-r--r-- | numpy/lib/index_tricks.py | 2 | ||||
-rw-r--r-- | numpy/lib/tests/test_index_tricks.py | 9 |
2 files changed, 10 insertions, 1 deletions
diff --git a/numpy/lib/index_tricks.py b/numpy/lib/index_tricks.py index cece8ac8d..c68bf2634 100644 --- a/numpy/lib/index_tricks.py +++ b/numpy/lib/index_tricks.py @@ -80,7 +80,7 @@ def ix_(*args): new = new.astype(_nx.intp) if issubdtype(new.dtype, _nx.bool_): new, = new.nonzero() - new.shape = (1,)*k + (new.size,) + (1,)*(nd-k-1) + new = new.reshape((1,)*k + (new.size,) + (1,)*(nd-k-1)) out.append(new) return tuple(out) diff --git a/numpy/lib/tests/test_index_tricks.py b/numpy/lib/tests/test_index_tricks.py index 0e3c98ee1..bb2ae1509 100644 --- a/numpy/lib/tests/test_index_tricks.py +++ b/numpy/lib/tests/test_index_tricks.py @@ -196,6 +196,15 @@ class TestIx_(TestCase): idx2d = [[1, 2, 3], [4, 5, 6]] assert_raises(ValueError, np.ix_, idx2d) + def test_repeated_input(self): + length_of_vector = 5 + x = np.arange(length_of_vector) + out = ix_(x, x) + assert_equal(out[0].shape, (length_of_vector, 1)) + assert_equal(out[1].shape, (1, length_of_vector)) + # check that input shape is not modified + assert_equal(x.shape, (length_of_vector,)) + def test_c_(): a = np.c_[np.array([[1, 2, 3]]), 0, 0, np.array([[4, 5, 6]])] |