Error in scipy sparse: multiplication with coo_matrix copy changes the data and the format of the multiplied
Ergun Bicici <[email protected]>
| Newsgroups | gmane.comp.python.scientific.user |
|---|---|
| Message-ID | <CAB2pGneVpDp3VFybR+pa=eiA=MW83vG=hWiTrxbkv9JqWOpDEg@mail.gmail.com> |
After multiplying a coo_matrix from scipy.sparse with its copy, the copy's
format changes to column-major and hence its data change while the original
data remains the same.
Example:
import numpy, scipy
from scipy.sparse import coo_matrix, csc_matrix
a = numpy.random.randn(4,7)
print ('a:', a)
b = coo_matrix(a)
c = b.copy()
print ('c before (coo_matrix):', c)
print ('c data before (coo_matrix):', c.data)
b.multiply(c)
print ('c after (coo_matrix):', c)
print ('c data after (coo_matrix):', c.data)
a: [[ 0.80168251 -1.39944231 0.25345622 1.42371329 -0.12530735
0.50449369
1.07289013]
[ 0.45875588 -0.15916679 -0.42632756 0.56484416 -1.46640872 1.42488646
0.03532664]
[ 0.72752298 1.34140445 -0.37043453 0.78127267 0.01084105 -2.08957963
-0.10899932]
[-0.02555597 -0.87197938 -0.76835675 0.82776032 -2.06292275 -1.2911363
-0.72253431]]
c before (coo_matrix): (0, 0) 0.801682509603
(0, 1) -1.39944230956
(0, 2) 0.253456223565
(0, 3) 1.4237132942
(0, 4) -0.125307347426
(0, 5) 0.504493692248
(0, 6) 1.07289013113
(1, 0) 0.458755875333
(1, 1) -0.159166794146
(1, 2) -0.426327564398
(1, 3) 0.564844163879
(1, 4) -1.46640871661
(1, 5) 1.42488646441
(1, 6) 0.0353266410166
(2, 0) 0.727522979291
(2, 1) 1.34140444948
(2, 2) -0.370434529077
(2, 3) 0.781272667369
(2, 4) 0.0108410499861
(2, 5) -2.08957962801
(2, 6) -0.108999316299
(3, 0) -0.0255559745129
(3, 1) -0.871979375733
(3, 2) -0.768356754242
(3, 3) 0.827760318972
(3, 4) -2.0629227477
(3, 5) -1.29113629796
(3, 6) -0.722534309773
c data before (coo_matrix): [ 0.80168251 -1.39944231 0.25345622
1.42371329 -0.12530735 0.50449369
1.07289013 0.45875588 -0.15916679 -0.42632756 0.56484416 -1.46640872
1.42488646 0.03532664 0.72752298 1.34140445 -0.37043453 0.78127267
0.01084105 -2.08957963 -0.10899932 -0.02555597 -0.87197938 -0.76835675
0.82776032 -2.06292275 -1.2911363 -0.72253431]
c after (coo_matrix): (0, 0) 0.801682509603
(1, 0) 0.458755875333
(2, 0) 0.727522979291
(3, 0) -0.0255559745129
(0, 1) -1.39944230956
(1, 1) -0.159166794146
(2, 1) 1.34140444948
(3, 1) -0.871979375733
(0, 2) 0.253456223565
(1, 2) -0.426327564398
(2, 2) -0.370434529077
(3, 2) -0.768356754242
(0, 3) 1.4237132942
(1, 3) 0.564844163879
(2, 3) 0.781272667369
(3, 3) 0.827760318972
(0, 4) -0.125307347426
(1, 4) -1.46640871661
(2, 4) 0.0108410499861
(3, 4) -2.0629227477
(0, 5) 0.504493692248
(1, 5) 1.42488646441
(2, 5) -2.08957962801
(3, 5) -1.29113629796
(0, 6) 1.07289013113
(1, 6) 0.0353266410166
(2, 6) -0.108999316299
(3, 6) -0.722534309773
c data after (coo_matrix): [ 0.80168251 0.45875588 0.72752298 -0.02555597
-1.39944231 -0.15916679
1.34140445 -0.87197938 0.25345622 -0.42632756 -0.37043453 -0.76835675
1.42371329 0.56484416 0.78127267 0.82776032 -0.12530735 -1.46640872
0.01084105 -2.06292275 0.50449369 1.42488646 -2.08957963 -1.2911363
1.07289013 0.03532664 -0.10899932 -0.72253431]
Best Regards,
Ergun
Ergun Biçici
http://bicici.github.com/ <http://ergunbicici.blogspot.com/>
_______________________________________________
SciPy-User mailing list
[email protected]
https://mail.python.org/mailman/listinfo/scipy-user