@@ -397,7 +397,7 @@ def todense(self):
397397 See Also
398398 --------
399399 - [`sparse.DOK.todense`][] : Equivalent `DOK` array method.
400- - [`scipy.sparse.coo_matrix .todense`][] : Equivalent Scipy method.
400+ - [`scipy.sparse.coo_array .todense`][] : Equivalent Scipy method.
401401
402402 Examples
403403 --------
@@ -451,11 +451,14 @@ def from_scipy_sparse(cls, x, /, *, fill_value=None):
451451 x .eliminate_zeros ()
452452 x .sum_duplicates ()
453453
454- coords = np .empty ((2 , x .nnz ), dtype = x .row .dtype )
455- coords [0 , :] = x .row
456- coords [1 , :] = x .col
454+ def _coords (x ):
455+ c = getattr (x , "coords" , None )
456+ if c is None : # legacy support for SciPy sparse matrices
457+ c = (x .row , x .col )
458+ return c
459+
457460 return COO (
458- coords ,
461+ _coords ( x ) ,
459462 x .data ,
460463 shape = x .shape ,
461464 has_duplicates = not x .has_canonical_format ,
@@ -562,7 +565,7 @@ def dtype(self):
562565 See Also
563566 --------
564567 - [`numpy.ndarray.dtype`][] : Numpy equivalent property.
565- - [`scipy.sparse.coo_matrix .dtype`][] : Scipy equivalent property.
568+ - [`scipy.sparse.coo_array .dtype`][] : Scipy equivalent property.
566569
567570 Examples
568571 --------
@@ -590,7 +593,7 @@ def nnz(self):
590593 --------
591594 - [`sparse.DOK.nnz`][] : Equivalent [`sparse.DOK`][] array property.
592595 - [`numpy.count_nonzero`][] : A similar Numpy function.
593- - [`scipy.sparse.coo_matrix .nnz`][] : The Scipy equivalent property.
596+ - [`scipy.sparse.coo_array .nnz`][] : The Scipy equivalent property.
594597
595598 Examples
596599 --------
@@ -945,7 +948,7 @@ def dot(self, other):
945948 --------
946949 - [`sparse.dot`][] : Equivalent function for two arguments.
947950 - [`numpy.dot`][] : Numpy equivalent function.
948- - [`scipy.sparse.coo_matrix .dot`][] : Scipy equivalent function.
951+ - [`scipy.sparse.coo_array .dot`][] : Scipy equivalent function.
949952
950953 Examples
951954 --------
@@ -1160,7 +1163,7 @@ def squeeze(self, axis=None):
11601163
11611164 def to_scipy_sparse (self , / , * , accept_fv = None ):
11621165 """
1163- Converts this [`sparse.COO`][] object into a [`scipy.sparse.coo_matrix `][].
1166+ Converts this [`sparse.COO`][] object into a [`scipy.sparse.coo_array `][].
11641167
11651168 Parameters
11661169 ----------
@@ -1169,7 +1172,7 @@ def to_scipy_sparse(self, /, *, accept_fv=None):
11691172
11701173 Returns
11711174 -------
1172- scipy.sparse.coo_matrix
1175+ scipy.sparse.coo_array
11731176 The converted Scipy sparse matrix.
11741177
11751178 Raises
@@ -1181,17 +1184,14 @@ def to_scipy_sparse(self, /, *, accept_fv=None):
11811184
11821185 See Also
11831186 --------
1184- - [`sparse.COO.tocsr`][] : Convert to a [`scipy.sparse.csr_matrix `][].
1185- - [`sparse.COO.tocsc`][] : Convert to a [`scipy.sparse.csc_matrix `][].
1187+ - [`sparse.COO.tocsr`][] : Convert to a [`scipy.sparse.csr_array `][].
1188+ - [`sparse.COO.tocsc`][] : Convert to a [`scipy.sparse.csc_array `][].
11861189 """
11871190 import scipy .sparse
11881191
11891192 check_fill_value (self , accept_fv = accept_fv )
11901193
1191- if self .ndim != 2 :
1192- raise ValueError ("Can only convert a 2-dimensional array to a Scipy sparse matrix." )
1193-
1194- result = scipy .sparse .coo_matrix ((self .data , (self .coords [0 ], self .coords [1 ])), shape = self .shape )
1194+ result = scipy .sparse .coo_array ((self .data , self .coords ), shape = self .shape )
11951195 result .has_canonical_format = True
11961196 return result
11971197
@@ -1206,15 +1206,15 @@ def _tocsr(self):
12061206 indptr = np .zeros (self .shape [0 ] + 1 , dtype = np .int64 )
12071207 np .cumsum (np .bincount (row , minlength = self .shape [0 ]), out = indptr [1 :])
12081208
1209- return scipy .sparse .csr_matrix ((self .data , col , indptr ), shape = self .shape )
1209+ return scipy .sparse .csr_array ((self .data , col , indptr ), shape = self .shape )
12101210
12111211 def tocsr (self ):
12121212 """
1213- Converts this array to a [`scipy.sparse.csr_matrix `][].
1213+ Converts this array to a [`scipy.sparse.csr_array `][].
12141214
12151215 Returns
12161216 -------
1217- scipy.sparse.csr_matrix
1217+ scipy.sparse.csr_array
12181218 The result of the conversion.
12191219
12201220 Raises
@@ -1226,9 +1226,9 @@ def tocsr(self):
12261226
12271227 See Also
12281228 --------
1229- - [`sparse.COO.tocsc`][] : Convert to a [`scipy.sparse.csc_matrix `][].
1230- - [`sparse.COO.to_scipy_sparse`][] : Convert to a [`scipy.sparse.coo_matrix `][].
1231- - [`scipy.sparse.coo_matrix .tocsr`][] : Equivalent Scipy function.
1229+ - [`sparse.COO.tocsc`][] : Convert to a [`scipy.sparse.csc_array `][].
1230+ - [`sparse.COO.to_scipy_sparse`][] : Convert to a [`scipy.sparse.coo_array `][].
1231+ - [`scipy.sparse.coo_array .tocsr`][] : Equivalent Scipy function.
12321232 """
12331233 check_zero_fill_value (self )
12341234
@@ -1250,11 +1250,11 @@ def tocsr(self):
12501250
12511251 def tocsc (self ):
12521252 """
1253- Converts this array to a [`scipy.sparse.csc_matrix `][].
1253+ Converts this array to a [`scipy.sparse.csc_array `][].
12541254
12551255 Returns
12561256 -------
1257- scipy.sparse.csc_matrix
1257+ scipy.sparse.csc_array
12581258 The result of the conversion.
12591259
12601260 Raises
@@ -1266,9 +1266,9 @@ def tocsc(self):
12661266
12671267 See Also
12681268 --------
1269- - [`sparse.COO.tocsr`][] : Convert to a [`scipy.sparse.csr_matrix `][].
1270- - [`sparse.COO.to_scipy_sparse`][] : Convert to a [`scipy.sparse.coo_matrix `][].
1271- - [`scipy.sparse.coo_matrix .tocsc`][] : Equivalent Scipy function.
1269+ - [`sparse.COO.tocsr`][] : Convert to a [`scipy.sparse.csr_array `][].
1270+ - [`sparse.COO.to_scipy_sparse`][] : Convert to a [`scipy.sparse.coo_array `][].
1271+ - [`scipy.sparse.coo_array .tocsc`][] : Equivalent Scipy function.
12721272 """
12731273 check_zero_fill_value (self )
12741274
@@ -1320,7 +1320,7 @@ def _sum_duplicates(self):
13201320
13211321 See Also
13221322 --------
1323- scipy.sparse.coo_matrix .sum_duplicates : Equivalent Scipy function.
1323+ scipy.sparse.coo_array .sum_duplicates : Equivalent Scipy function.
13241324
13251325 Examples
13261326 --------
0 commit comments