From 819b3a8a019469774a5343afd87ec71ec696bf80 Mon Sep 17 00:00:00 2001 From: Garrett-R Date: Mon, 8 Dec 2014 20:33:48 -0800 Subject: BUG: Closes #2015: diag returns ndarray If x is a matrix, np.diag(x) and np.diagonal(x) now return matrices instead of arrays. Both of these cause x.diagonal() to be called. That means they return row vectors (just like x.flatten(), x.ravel(), x.cumprod(), etc.) --- numpy/matrixlib/tests/test_numeric.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'numpy/matrixlib/tests/test_numeric.py') diff --git a/numpy/matrixlib/tests/test_numeric.py b/numpy/matrixlib/tests/test_numeric.py index 3588de5e6..91dc92d2e 100644 --- a/numpy/matrixlib/tests/test_numeric.py +++ b/numpy/matrixlib/tests/test_numeric.py @@ -2,12 +2,22 @@ from __future__ import division, absolute_import, print_function from numpy.testing import assert_equal, TestCase, run_module_suite from numpy.core import ones -from numpy import matrix +from numpy import matrix, diagonal, diag class TestDot(TestCase): def test_matscalar(self): b1 = matrix(ones((3, 3), dtype=complex)) assert_equal(b1*1.0, b1) + +def test_diagonal(): + b1 = matrix([[1,2],[3,4]]) + diag_b1 = matrix([[1, 4]]) + + assert_equal(b1.diagonal(), diag_b1) + assert_equal(diagonal(b1), diag_b1) + assert_equal(diag(b1), diag_b1) + + if __name__ == "__main__": run_module_suite() -- cgit v1.2.1