Skip to content

Commit 028647d

Browse files
committed
BUG: np.matrix does not return an array when given a full index ending in ...
This is similar to numpygh-8684, but for matrices instead of masked arrays. Fixing this for all the possible placements of `...` is way harder, but this is better than nothing
1 parent 88f8310 commit 028647d

2 files changed

Lines changed: 13 additions & 2 deletions

File tree

‎numpy/matrixlib/defmatrix.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,8 +289,8 @@ def __getitem__(self, index):
289289
return out
290290

291291
if out.ndim == 0:
292-
return out[()]
293-
if out.ndim == 1:
292+
out.shape = (1, 1)
293+
elif out.ndim == 1:
294294
sh = out.shape[0]
295295
# Determine when we should have a column array
296296
try:

‎numpy/matrixlib/tests/test_defmatrix.py‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,17 @@ def test_list_indexing(self):
394394
assert_array_equal(x[:, [1, 0]], x[:, ::-1])
395395
assert_array_equal(x[[2, 1, 0],:], x[::-1,:])
396396

397+
def test_ellipsis_indexing(self):
398+
A = np.arange(6)
399+
A.shape = (3, 2)
400+
x = asmatrix(A)
401+
402+
# Indexing with ... would normally return a 0d array, but np.matrix
403+
# promotes to 2d as usual
404+
x_item = x[1, 1, ...]
405+
assert_(type(x_item) is matrix)
406+
assert_equal(x_item.shape, (1, 1))
407+
397408

398409
class TestPower(object):
399410
def test_returntype(self):

0 commit comments

Comments
 (0)