summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--numpy/core/fromnumeric.py11
-rw-r--r--numpy/matrixlib/tests/test_defmatrix.py10
2 files changed, 13 insertions, 8 deletions
diff --git a/numpy/core/fromnumeric.py b/numpy/core/fromnumeric.py
index da61fc187..2a527a4a4 100644
--- a/numpy/core/fromnumeric.py
+++ b/numpy/core/fromnumeric.py
@@ -1376,8 +1376,10 @@ def ravel(a, order='C'):
Returns
-------
y : array_like
- Array of the same type as `a`, and of shape ``(a.size,)``
- or ``(1, a.size)`` for matrices.
+ If `a` is a matrix, y is a 1-D ndarray, otherwise y is an array of
+ the same subtype as `a`. The shape of the returned array is
+ ``(a.size,)``. Matrices are special cased for backward
+ compatibility.
See Also
--------
@@ -1435,7 +1437,10 @@ def ravel(a, order='C'):
array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11])
"""
- return asanyarray(a).ravel(order)
+ if isinstance(a, np.matrix):
+ return asarray(a).ravel(order)
+ else:
+ return asanyarray(a).ravel(order)
def nonzero(a):
diff --git a/numpy/matrixlib/tests/test_defmatrix.py b/numpy/matrixlib/tests/test_defmatrix.py
index 93843c55c..f3a8e72ca 100644
--- a/numpy/matrixlib/tests/test_defmatrix.py
+++ b/numpy/matrixlib/tests/test_defmatrix.py
@@ -409,7 +409,7 @@ class TestShape(TestCase):
def test_numpy_ravel(self):
assert_equal(np.ravel(self.a).shape, (2,))
- assert_equal(np.ravel(self.m).shape, (1, 2))
+ assert_equal(np.ravel(self.m).shape, (2,))
def test_member_ravel(self):
assert_equal(self.a.ravel().shape, (2,))
@@ -426,10 +426,10 @@ class TestShape(TestCase):
assert_equal(np.ravel(x.T), [1, 4, 2, 5, 3, 6])
assert_equal(np.ravel(x.T, order='A'), [1, 2, 3, 4, 5, 6])
x = matrix([[1, 2, 3], [4, 5, 6]])
- assert_equal(np.ravel(x), [[1, 2, 3, 4, 5, 6]])
- assert_equal(np.ravel(x, order='F'), [[1, 4, 2, 5, 3, 6]])
- assert_equal(np.ravel(x.T), [[1, 4, 2, 5, 3, 6]])
- assert_equal(np.ravel(x.T, order='A'), [[1, 2, 3, 4, 5, 6]])
+ assert_equal(np.ravel(x), [1, 2, 3, 4, 5, 6])
+ assert_equal(np.ravel(x, order='F'), [1, 4, 2, 5, 3, 6])
+ assert_equal(np.ravel(x.T), [1, 4, 2, 5, 3, 6])
+ assert_equal(np.ravel(x.T, order='A'), [1, 2, 3, 4, 5, 6])
def test_matrix_ravel_order(self):
x = matrix([[1, 2, 3], [4, 5, 6]])