We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
BUG: scipy.sparse.linalg.norm does not work on sparse arrays
### Describe your issue.

Greetings.
As from the document of sparse matrices : https://docs.scipy.org/doc/scipy/reference/sparse.html,
both "Sparse array classes" and "Sparse matrix classes" belong to sparse matrices.

Also, from the document of sparse.linalg.norm, the input array arr is only mentioned as sparse matrix, 
so I expect that norm function should work on both sparse array classes and sparse matrix classes.

However, norm does not work on sparse array classes, and the error message is shown below.
I think the main reason of this is that: Since the intermediate output M in: https://github.com/scipy/scipy/blob/main/scipy/sparse/linalg/_norm.py#L180
returns numpy.ndarray rather than numpy.matrix, and numpy.ndarray does not have attribute A.

Since sparse array classes will pass issparse(), maybe we should add another assert for this if norm only supports sparse matrix classes.

Thank you.

### Reproducing Code Example

```python
import numpy as np
from scipy.sparse import coo_array
from scipy.sparse import linalg
row  = np.array([0, 0, 1, 1])
col  = np.array([0, 1, 2, 3])
data = np.array([4, 5, 7, 9])
test_arr = coo_array((data, (row, col)), shape=(2, 4))
linalg.norm(test_arr, ord=1, axis=0)
```


### Error message

```shell
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Input In [73], in <cell line: 8>()
      6 data = np.array([4, 5, 7, 9])
      7 test_arr = coo_array((data, (row, col)), shape=(2, 4))
----> 8 linalg.norm(test_arr, ord=1, axis=0)

File ~/.local/lib/python3.9/site-packages/scipy/sparse/linalg/_norm.py:180, in norm(x, ord, axis)
    178             raise ValueError('Invalid norm order for vectors.') from e
    179         M = np.power(abs(x).power(ord).sum(axis=a), 1 / ord)
--> 180     return M.A.ravel()
    181 else:
    182     raise ValueError("Improper number of dimensions to norm.")

AttributeError: 'numpy.ndarray' object has no attribute 'A'
```


### SciPy/NumPy/Python version information

1.8.0 1.22.3 sys.version_info(major=3, minor=9, micro=10, releaselevel='final', serial=0)

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `scipy/sparse/linalg/_norm.py`
Content:
```
1 """Sparse matrix norms.
2 
3 """
4 import numpy as np
5 from scipy.sparse import issparse
6 
7 from numpy import Inf, sqrt, abs
8 
9 __all__ = ['norm']
10 
11 
12 def _sparse_frobenius_norm(x):
13     if np.issubdtype(x.dtype, np.complexfloating):
14         sqnorm = abs(x).power(2).sum()
15     else:
16         sqnorm = x.power(2).sum()
17     return sqrt(sqnorm)
18 
19 
20 def norm(x, ord=None, axis=None):
21     """
22     Norm of a sparse matrix
23 
24     This function is able to return one of seven different matrix norms,
25     depending on the value of the ``ord`` parameter.
26 
27     Parameters
28     ----------
29     x : a sparse matrix
30         Input sparse matrix.
31     ord : {non-zero int, inf, -inf, 'fro'}, optional
32         Order of the norm (see table under ``Notes``). inf means numpy's
33         `inf` object.
34     axis : {int, 2-tuple of ints, None}, optional
35         If `axis` is an integer, it specifies the axis of `x` along which to
36         compute the vector norms.  If `axis` is a 2-tuple, it specifies the
37         axes that hold 2-D matrices, and the matrix norms of these matrices
38         are computed.  If `axis` is None then either a vector norm (when `x`
39         is 1-D) or a matrix norm (when `x` is 2-D) is returned.
40 
41     Returns
42     -------
43     n : float or ndarray
44 
45     Notes
46     -----
47     Some of the ord are not implemented because some associated functions like,
48     _multi_svd_norm, are not yet available for sparse matrix.
49 
50     This docstring is modified based on numpy.linalg.norm.
51     https://github.com/numpy/numpy/blob/main/numpy/linalg/linalg.py
52 
53     The following norms can be calculated:
54 
55     =====  ============================
56     ord    norm for sparse matrices
57     =====  ============================
58     None   Frobenius norm
59     'fro'  Frobenius norm
60     inf    max(sum(abs(x), axis=1))
61     -inf   min(sum(abs(x), axis=1))
62     0      abs(x).sum(axis=axis)
63     1      max(sum(abs(x), axis=0))
64     -1     min(sum(abs(x), axis=0))
65     2      Not implemented
66     -2     Not implemented
67     other  Not implemented
68     =====  ============================
69 
70     The Frobenius norm is given by [1]_:
71 
72         :math:`||A||_F = [\\sum_{i,j} abs(a_{i,j})^2]^{1/2}`
73 
74     References
75     ----------
76     .. [1] G. H. Golub and C. F. Van Loan, *Matrix Computations*,
77         Baltimore, MD, Johns Hopkins University Press, 1985, pg. 15
78 
79     Examples
80     --------
81     >>> from scipy.sparse import *
82     >>> import numpy as np
83     >>> from scipy.sparse.linalg import norm
84     >>> a = np.arange(9) - 4
85     >>> a
86     array([-4, -3, -2, -1, 0, 1, 2, 3, 4])
87     >>> b = a.reshape((3, 3))
88     >>> b
89     array([[-4, -3, -2],
90            [-1, 0, 1],
91            [ 2, 3, 4]])
92 
93     >>> b = csr_matrix(b)
94     >>> norm(b)
95     7.745966692414834
96     >>> norm(b, 'fro')
97     7.745966692414834
98     >>> norm(b, np.inf)
99     9
100     >>> norm(b, -np.inf)
101     2
102     >>> norm(b, 1)
103     7
104     >>> norm(b, -1)
105     6
106 
107     """
108     if not issparse(x):
109         raise TypeError("input is not sparse. use numpy.linalg.norm")
110 
111     # Check the default case first and handle it immediately.
112     if axis is None and ord in (None, 'fro', 'f'):
113         return _sparse_frobenius_norm(x)
114 
115     # Some norms require functions that are not implemented for all types.
116     x = x.tocsr()
117 
118     if axis is None:
119         axis = (0, 1)
120     elif not isinstance(axis, tuple):
121         msg = "'axis' must be None, an integer or a tuple of integers"
122         try:
123             int_axis = int(axis)
124         except TypeError as e:
125             raise TypeError(msg) from e
126         if axis != int_axis:
127             raise TypeError(msg)
128         axis = (int_axis,)
129 
130     nd = 2
131     if len(axis) == 2:
132         row_axis, col_axis = axis
133         if not (-nd <= row_axis < nd and -nd <= col_axis < nd):
134             raise ValueError('Invalid axis %r for an array with shape %r' %
135                              (axis, x.shape))
136         if row_axis % nd == col_axis % nd:
137             raise ValueError('Duplicate axes given.')
138         if ord == 2:
139             raise NotImplementedError
140             #return _multi_svd_norm(x, row_axis, col_axis, amax)
141         elif ord == -2:
142             raise NotImplementedError
143             #return _multi_svd_norm(x, row_axis, col_axis, amin)
144         elif ord == 1:
145             return abs(x).sum(axis=row_axis).max(axis=col_axis)[0,0]
146         elif ord == Inf:
147             return abs(x).sum(axis=col_axis).max(axis=row_axis)[0,0]
148         elif ord == -1:
149             return abs(x).sum(axis=row_axis).min(axis=col_axis)[0,0]
150         elif ord == -Inf:
151             return abs(x).sum(axis=col_axis).min(axis=row_axis)[0,0]
152         elif ord in (None, 'f', 'fro'):
153             # The axis order does not matter for this norm.
154             return _sparse_frobenius_norm(x)
155         else:
156             raise ValueError("Invalid norm order for matrices.")
157     elif len(axis) == 1:
158         a, = axis
159         if not (-nd <= a < nd):
160             raise ValueError('Invalid axis %r for an array with shape %r' %
161                              (axis, x.shape))
162         if ord == Inf:
163             M = abs(x).max(axis=a)
164         elif ord == -Inf:
165             M = abs(x).min(axis=a)
166         elif ord == 0:
167             # Zero norm
168             M = (x != 0).sum(axis=a)
169         elif ord == 1:
170             # special case for speedup
171             M = abs(x).sum(axis=a)
172         elif ord in (2, None):
173             M = sqrt(abs(x).power(2).sum(axis=a))
174         else:
175             try:
176                 ord + 1
177             except TypeError as e:
178                 raise ValueError('Invalid norm order for vectors.') from e
179             M = np.power(abs(x).power(ord).sum(axis=a), 1 / ord)
180         return M.A.ravel()
181     else:
182         raise ValueError("Improper number of dimensions to norm.")
183
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/scipy/sparse/linalg/_norm.py b/scipy/sparse/linalg/_norm.py
--- a/scipy/sparse/linalg/_norm.py
+++ b/scipy/sparse/linalg/_norm.py
@@ -177,6 +177,11 @@
             except TypeError as e:
                 raise ValueError('Invalid norm order for vectors.') from e
             M = np.power(abs(x).power(ord).sum(axis=a), 1 / ord)
-        return M.A.ravel()
+        if hasattr(M, 'toarray'):
+            return M.toarray().ravel()
+        elif hasattr(M, 'A'):
+            return M.A.ravel()
+        else:
+            return M.ravel()
     else:
         raise ValueError("Improper number of dimensions to norm.")

{"golden_diff": "diff --git a/scipy/sparse/linalg/_norm.py b/scipy/sparse/linalg/_norm.py\n--- a/scipy/sparse/linalg/_norm.py\n+++ b/scipy/sparse/linalg/_norm.py\n@@ -177,6 +177,11 @@\n             except TypeError as e:\n                 raise ValueError('Invalid norm order for vectors.') from e\n             M = np.power(abs(x).power(ord).sum(axis=a), 1 / ord)\n-        return M.A.ravel()\n+        if hasattr(M, 'toarray'):\n+            return M.toarray().ravel()\n+        elif hasattr(M, 'A'):\n+            return M.A.ravel()\n+        else:\n+            return M.ravel()\n     else:\n         raise ValueError(\"Improper number of dimensions to norm.\")\n", "issue": "BUG: scipy.sparse.linalg.norm does not work on sparse arrays\n### Describe your issue.\n\nGreetings.\r\nAs from the document of sparse matrices : https://docs.scipy.org/doc/scipy/reference/sparse.html,\r\nboth \"Sparse array classes\" and \"Sparse matrix classes\" belong to sparse matrices.\r\n\r\nAlso, from the document of sparse.linalg.norm, the input array arr is only mentioned as sparse matrix, \r\nso I expect that norm function should work on both sparse array classes and sparse matrix classes.\r\n\r\nHowever, norm does not work on sparse array classes, and the error message is shown below.\r\nI think the main reason of this is that: Since the intermediate output M in: https://github.com/scipy/scipy/blob/main/scipy/sparse/linalg/_norm.py#L180\r\nreturns numpy.ndarray rather than numpy.matrix, and numpy.ndarray does not have attribute A.\r\n\r\nSince sparse array classes will pass issparse(), maybe we should add another assert for this if norm only supports sparse matrix classes.\r\n\r\nThank you.\n\n### Reproducing Code Example\n\n```python\nimport numpy as np\r\nfrom scipy.sparse import coo_array\r\nfrom scipy.sparse import linalg\r\nrow  = np.array([0, 0, 1, 1])\r\ncol  = np.array([0, 1, 2, 3])\r\ndata = np.array([4, 5, 7, 9])\r\ntest_arr = coo_array((data, (row, col)), shape=(2, 4))\r\nlinalg.norm(test_arr, ord=1, axis=0)\n```\n\n\n### Error message\n\n```shell\n---------------------------------------------------------------------------\r\nAttributeError                            Traceback (most recent call last)\r\nInput In [73], in <cell line: 8>()\r\n      6 data = np.array([4, 5, 7, 9])\r\n      7 test_arr = coo_array((data, (row, col)), shape=(2, 4))\r\n----> 8 linalg.norm(test_arr, ord=1, axis=0)\r\n\r\nFile ~/.local/lib/python3.9/site-packages/scipy/sparse/linalg/_norm.py:180, in norm(x, ord, axis)\r\n    178             raise ValueError('Invalid norm order for vectors.') from e\r\n    179         M = np.power(abs(x).power(ord).sum(axis=a), 1 / ord)\r\n--> 180     return M.A.ravel()\r\n    181 else:\r\n    182     raise ValueError(\"Improper number of dimensions to norm.\")\r\n\r\nAttributeError: 'numpy.ndarray' object has no attribute 'A'\n```\n\n\n### SciPy/NumPy/Python version information\n\n1.8.0 1.22.3 sys.version_info(major=3, minor=9, micro=10, releaselevel='final', serial=0)\n", "before_files": [{"content": "\"\"\"Sparse matrix norms.\n\n\"\"\"\nimport numpy as np\nfrom scipy.sparse import issparse\n\nfrom numpy import Inf, sqrt, abs\n\n__all__ = ['norm']\n\n\ndef _sparse_frobenius_norm(x):\n    if np.issubdtype(x.dtype, np.complexfloating):\n        sqnorm = abs(x).power(2).sum()\n    else:\n        sqnorm = x.power(2).sum()\n    return sqrt(sqnorm)\n\n\ndef norm(x, ord=None, axis=None):\n    \"\"\"\n    Norm of a sparse matrix\n\n    This function is able to return one of seven different matrix norms,\n    depending on the value of the ``ord`` parameter.\n\n    Parameters\n    ----------\n    x : a sparse matrix\n        Input sparse matrix.\n    ord : {non-zero int, inf, -inf, 'fro'}, optional\n        Order of the norm (see table under ``Notes``). inf means numpy's\n        `inf` object.\n    axis : {int, 2-tuple of ints, None}, optional\n        If `axis` is an integer, it specifies the axis of `x` along which to\n        compute the vector norms.  If `axis` is a 2-tuple, it specifies the\n        axes that hold 2-D matrices, and the matrix norms of these matrices\n        are computed.  If `axis` is None then either a vector norm (when `x`\n        is 1-D) or a matrix norm (when `x` is 2-D) is returned.\n\n    Returns\n    -------\n    n : float or ndarray\n\n    Notes\n    -----\n    Some of the ord are not implemented because some associated functions like,\n    _multi_svd_norm, are not yet available for sparse matrix.\n\n    This docstring is modified based on numpy.linalg.norm.\n    https://github.com/numpy/numpy/blob/main/numpy/linalg/linalg.py\n\n    The following norms can be calculated:\n\n    =====  ============================\n    ord    norm for sparse matrices\n    =====  ============================\n    None   Frobenius norm\n    'fro'  Frobenius norm\n    inf    max(sum(abs(x), axis=1))\n    -inf   min(sum(abs(x), axis=1))\n    0      abs(x).sum(axis=axis)\n    1      max(sum(abs(x), axis=0))\n    -1     min(sum(abs(x), axis=0))\n    2      Not implemented\n    -2     Not implemented\n    other  Not implemented\n    =====  ============================\n\n    The Frobenius norm is given by [1]_:\n\n        :math:`||A||_F = [\\\\sum_{i,j} abs(a_{i,j})^2]^{1/2}`\n\n    References\n    ----------\n    .. [1] G. H. Golub and C. F. Van Loan, *Matrix Computations*,\n        Baltimore, MD, Johns Hopkins University Press, 1985, pg. 15\n\n    Examples\n    --------\n    >>> from scipy.sparse import *\n    >>> import numpy as np\n    >>> from scipy.sparse.linalg import norm\n    >>> a = np.arange(9) - 4\n    >>> a\n    array([-4, -3, -2, -1, 0, 1, 2, 3, 4])\n    >>> b = a.reshape((3, 3))\n    >>> b\n    array([[-4, -3, -2],\n           [-1, 0, 1],\n           [ 2, 3, 4]])\n\n    >>> b = csr_matrix(b)\n    >>> norm(b)\n    7.745966692414834\n    >>> norm(b, 'fro')\n    7.745966692414834\n    >>> norm(b, np.inf)\n    9\n    >>> norm(b, -np.inf)\n    2\n    >>> norm(b, 1)\n    7\n    >>> norm(b, -1)\n    6\n\n    \"\"\"\n    if not issparse(x):\n        raise TypeError(\"input is not sparse. use numpy.linalg.norm\")\n\n    # Check the default case first and handle it immediately.\n    if axis is None and ord in (None, 'fro', 'f'):\n        return _sparse_frobenius_norm(x)\n\n    # Some norms require functions that are not implemented for all types.\n    x = x.tocsr()\n\n    if axis is None:\n        axis = (0, 1)\n    elif not isinstance(axis, tuple):\n        msg = \"'axis' must be None, an integer or a tuple of integers\"\n        try:\n            int_axis = int(axis)\n        except TypeError as e:\n            raise TypeError(msg) from e\n        if axis != int_axis:\n            raise TypeError(msg)\n        axis = (int_axis,)\n\n    nd = 2\n    if len(axis) == 2:\n        row_axis, col_axis = axis\n        if not (-nd <= row_axis < nd and -nd <= col_axis < nd):\n            raise ValueError('Invalid axis %r for an array with shape %r' %\n                             (axis, x.shape))\n        if row_axis % nd == col_axis % nd:\n            raise ValueError('Duplicate axes given.')\n        if ord == 2:\n            raise NotImplementedError\n            #return _multi_svd_norm(x, row_axis, col_axis, amax)\n        elif ord == -2:\n            raise NotImplementedError\n            #return _multi_svd_norm(x, row_axis, col_axis, amin)\n        elif ord == 1:\n            return abs(x).sum(axis=row_axis).max(axis=col_axis)[0,0]\n        elif ord == Inf:\n            return abs(x).sum(axis=col_axis).max(axis=row_axis)[0,0]\n        elif ord == -1:\n            return abs(x).sum(axis=row_axis).min(axis=col_axis)[0,0]\n        elif ord == -Inf:\n            return abs(x).sum(axis=col_axis).min(axis=row_axis)[0,0]\n        elif ord in (None, 'f', 'fro'):\n            # The axis order does not matter for this norm.\n            return _sparse_frobenius_norm(x)\n        else:\n            raise ValueError(\"Invalid norm order for matrices.\")\n    elif len(axis) == 1:\n        a, = axis\n        if not (-nd <= a < nd):\n            raise ValueError('Invalid axis %r for an array with shape %r' %\n                             (axis, x.shape))\n        if ord == Inf:\n            M = abs(x).max(axis=a)\n        elif ord == -Inf:\n            M = abs(x).min(axis=a)\n        elif ord == 0:\n            # Zero norm\n            M = (x != 0).sum(axis=a)\n        elif ord == 1:\n            # special case for speedup\n            M = abs(x).sum(axis=a)\n        elif ord in (2, None):\n            M = sqrt(abs(x).power(2).sum(axis=a))\n        else:\n            try:\n                ord + 1\n            except TypeError as e:\n                raise ValueError('Invalid norm order for vectors.') from e\n            M = np.power(abs(x).power(ord).sum(axis=a), 1 / ord)\n        return M.A.ravel()\n    else:\n        raise ValueError(\"Improper number of dimensions to norm.\")\n", "path": "scipy/sparse/linalg/_norm.py"}], "after_files": [{"content": "\"\"\"Sparse matrix norms.\n\n\"\"\"\nimport numpy as np\nfrom scipy.sparse import issparse\n\nfrom numpy import Inf, sqrt, abs\n\n__all__ = ['norm']\n\n\ndef _sparse_frobenius_norm(x):\n    if np.issubdtype(x.dtype, np.complexfloating):\n        sqnorm = abs(x).power(2).sum()\n    else:\n        sqnorm = x.power(2).sum()\n    return sqrt(sqnorm)\n\n\ndef norm(x, ord=None, axis=None):\n    \"\"\"\n    Norm of a sparse matrix\n\n    This function is able to return one of seven different matrix norms,\n    depending on the value of the ``ord`` parameter.\n\n    Parameters\n    ----------\n    x : a sparse matrix\n        Input sparse matrix.\n    ord : {non-zero int, inf, -inf, 'fro'}, optional\n        Order of the norm (see table under ``Notes``). inf means numpy's\n        `inf` object.\n    axis : {int, 2-tuple of ints, None}, optional\n        If `axis` is an integer, it specifies the axis of `x` along which to\n        compute the vector norms.  If `axis` is a 2-tuple, it specifies the\n        axes that hold 2-D matrices, and the matrix norms of these matrices\n        are computed.  If `axis` is None then either a vector norm (when `x`\n        is 1-D) or a matrix norm (when `x` is 2-D) is returned.\n\n    Returns\n    -------\n    n : float or ndarray\n\n    Notes\n    -----\n    Some of the ord are not implemented because some associated functions like,\n    _multi_svd_norm, are not yet available for sparse matrix.\n\n    This docstring is modified based on numpy.linalg.norm.\n    https://github.com/numpy/numpy/blob/main/numpy/linalg/linalg.py\n\n    The following norms can be calculated:\n\n    =====  ============================\n    ord    norm for sparse matrices\n    =====  ============================\n    None   Frobenius norm\n    'fro'  Frobenius norm\n    inf    max(sum(abs(x), axis=1))\n    -inf   min(sum(abs(x), axis=1))\n    0      abs(x).sum(axis=axis)\n    1      max(sum(abs(x), axis=0))\n    -1     min(sum(abs(x), axis=0))\n    2      Not implemented\n    -2     Not implemented\n    other  Not implemented\n    =====  ============================\n\n    The Frobenius norm is given by [1]_:\n\n        :math:`||A||_F = [\\\\sum_{i,j} abs(a_{i,j})^2]^{1/2}`\n\n    References\n    ----------\n    .. [1] G. H. Golub and C. F. Van Loan, *Matrix Computations*,\n        Baltimore, MD, Johns Hopkins University Press, 1985, pg. 15\n\n    Examples\n    --------\n    >>> from scipy.sparse import *\n    >>> import numpy as np\n    >>> from scipy.sparse.linalg import norm\n    >>> a = np.arange(9) - 4\n    >>> a\n    array([-4, -3, -2, -1, 0, 1, 2, 3, 4])\n    >>> b = a.reshape((3, 3))\n    >>> b\n    array([[-4, -3, -2],\n           [-1, 0, 1],\n           [ 2, 3, 4]])\n\n    >>> b = csr_matrix(b)\n    >>> norm(b)\n    7.745966692414834\n    >>> norm(b, 'fro')\n    7.745966692414834\n    >>> norm(b, np.inf)\n    9\n    >>> norm(b, -np.inf)\n    2\n    >>> norm(b, 1)\n    7\n    >>> norm(b, -1)\n    6\n\n    \"\"\"\n    if not issparse(x):\n        raise TypeError(\"input is not sparse. use numpy.linalg.norm\")\n\n    # Check the default case first and handle it immediately.\n    if axis is None and ord in (None, 'fro', 'f'):\n        return _sparse_frobenius_norm(x)\n\n    # Some norms require functions that are not implemented for all types.\n    x = x.tocsr()\n\n    if axis is None:\n        axis = (0, 1)\n    elif not isinstance(axis, tuple):\n        msg = \"'axis' must be None, an integer or a tuple of integers\"\n        try:\n            int_axis = int(axis)\n        except TypeError as e:\n            raise TypeError(msg) from e\n        if axis != int_axis:\n            raise TypeError(msg)\n        axis = (int_axis,)\n\n    nd = 2\n    if len(axis) == 2:\n        row_axis, col_axis = axis\n        if not (-nd <= row_axis < nd and -nd <= col_axis < nd):\n            raise ValueError('Invalid axis %r for an array with shape %r' %\n                             (axis, x.shape))\n        if row_axis % nd == col_axis % nd:\n            raise ValueError('Duplicate axes given.')\n        if ord == 2:\n            raise NotImplementedError\n            #return _multi_svd_norm(x, row_axis, col_axis, amax)\n        elif ord == -2:\n            raise NotImplementedError\n            #return _multi_svd_norm(x, row_axis, col_axis, amin)\n        elif ord == 1:\n            return abs(x).sum(axis=row_axis).max(axis=col_axis)[0,0]\n        elif ord == Inf:\n            return abs(x).sum(axis=col_axis).max(axis=row_axis)[0,0]\n        elif ord == -1:\n            return abs(x).sum(axis=row_axis).min(axis=col_axis)[0,0]\n        elif ord == -Inf:\n            return abs(x).sum(axis=col_axis).min(axis=row_axis)[0,0]\n        elif ord in (None, 'f', 'fro'):\n            # The axis order does not matter for this norm.\n            return _sparse_frobenius_norm(x)\n        else:\n            raise ValueError(\"Invalid norm order for matrices.\")\n    elif len(axis) == 1:\n        a, = axis\n        if not (-nd <= a < nd):\n            raise ValueError('Invalid axis %r for an array with shape %r' %\n                             (axis, x.shape))\n        if ord == Inf:\n            M = abs(x).max(axis=a)\n        elif ord == -Inf:\n            M = abs(x).min(axis=a)\n        elif ord == 0:\n            # Zero norm\n            M = (x != 0).sum(axis=a)\n        elif ord == 1:\n            # special case for speedup\n            M = abs(x).sum(axis=a)\n        elif ord in (2, None):\n            M = sqrt(abs(x).power(2).sum(axis=a))\n        else:\n            try:\n                ord + 1\n            except TypeError as e:\n                raise ValueError('Invalid norm order for vectors.') from e\n            M = np.power(abs(x).power(ord).sum(axis=a), 1 / ord)\n        if hasattr(M, 'toarray'):\n            return M.toarray().ravel()\n        elif hasattr(M, 'A'):\n            return M.A.ravel()\n        else:\n            return M.ravel()\n    else:\n        raise ValueError(\"Improper number of dimensions to norm.\")\n", "path": "scipy/sparse/linalg/_norm.py"}]}