Re: Error in scipy sparse: multiplication with coo_matrix copy changes the data and the format of the multiplied

David Hagen <[email protected]>
Newsgroups gmane.comp.python.scientific.user
Message-ID <CALO6Ft7BCQTqKb5mzYd_k8zm0a5LXTuk8pYCFw6ZM6gC31cRsw@mail.gmail.com>
What version are you using? I am on 1.0.0 on Windows 7 and can't reproduce
this.


In [1]: 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.13836937 -0.44769877 -0.67486584 -0.18079949  0.68758066 -0.77756412
 0.77819897]
 [-0.07750618  0.45723152  0.45801638  0.69517378  0.03544761  0.09793786
 0.13236508]
 [-0.65393023  1.1196121   0.45519321  0.27690164 -1.28679679 -0.46791624
 0.59063279]
 [ 1.43179076  0.38644705 -0.27769729  1.09228815 -1.38605657 -1.39493734
-1.06365405]]
c before (coo_matrix):   (0, 0) 0.13836937102833774
  (0, 1)        -0.44769876721981233
  (0, 2)        -0.6748658374897415
  (0, 3)        -0.18079948538318338
  (0, 4)        0.6875806622877358
  (0, 5)        -0.7775641155122853
  (0, 6)        0.7781989700714793
  (1, 0)        -0.07750617928808383
  (1, 1)        0.4572315207281202
  (1, 2)        0.4580163825027164
  (1, 3)        0.6951737836620446
  (1, 4)        0.035447606524930446
  (1, 5)        0.09793785855383845
  (1, 6)        0.13236508271088915
  (2, 0)        -0.6539302277704122
  (2, 1)        1.1196120969391556
  (2, 2)        0.45519320523897316
  (2, 3)        0.27690163859596667
  (2, 4)        -1.2867967876681026
  (2, 5)        -0.4679162379777137
  (2, 6)        0.5906327892567922
  (3, 0)        1.4317907565386616
  (3, 1)        0.38644704937601526
  (3, 2)        -0.2776972862955177
  (3, 3)        1.0922881499931638
  (3, 4)        -1.3860565664680384
  (3, 5)        -1.3949373395890408
  (3, 6)        -1.0636540485066541
c data before (coo_matrix): [ 0.13836937 -0.44769877 -0.67486584
-0.18079949  0.68758066 -0.77756412
  0.77819897 -0.07750618  0.45723152  0.45801638  0.69517378  0.03544761
  0.09793786  0.13236508 -0.65393023  1.1196121   0.45519321  0.27690164
 -1.28679679 -0.46791624  0.59063279  1.43179076  0.38644705 -0.27769729
  1.09228815 -1.38605657 -1.39493734 -1.06365405]
c after (coo_matrix):   (0, 0)  0.13836937102833774
  (0, 1)        -0.44769876721981233
  (0, 2)        -0.6748658374897415
  (0, 3)        -0.18079948538318338
  (0, 4)        0.6875806622877358
  (0, 5)        -0.7775641155122853
  (0, 6)        0.7781989700714793
  (1, 0)        -0.07750617928808383
  (1, 1)        0.4572315207281202
  (1, 2)        0.4580163825027164
  (1, 3)        0.6951737836620446
  (1, 4)        0.035447606524930446
  (1, 5)        0.09793785855383845
  (1, 6)        0.13236508271088915
  (2, 0)        -0.6539302277704122
  (2, 1)        1.1196120969391556
  (2, 2)        0.45519320523897316
  (2, 3)        0.27690163859596667
  (2, 4)        -1.2867967876681026
  (2, 5)        -0.4679162379777137
  (2, 6)        0.5906327892567922
  (3, 0)        1.4317907565386616
  (3, 1)        0.38644704937601526
  (3, 2)        -0.2776972862955177
  (3, 3)        1.0922881499931638
  (3, 4)        -1.3860565664680384
  (3, 5)        -1.3949373395890408
  (3, 6)        -1.0636540485066541
c data after (coo_matrix): [ 0.13836937 -0.44769877 -0.67486584
-0.18079949  0.68758066 -0.77756412
  0.77819897 -0.07750618  0.45723152  0.45801638  0.69517378  0.03544761
  0.09793786  0.13236508 -0.65393023  1.1196121   0.45519321  0.27690164
 -1.28679679 -0.46791624  0.59063279  1.43179076  0.38644705 -0.27769729
  1.09228815 -1.38605657 -1.39493734 -1.06365405]

In [2]: scipy.version.version
Out[2]: '1.0.0'

_______________________________________________
SciPy-User mailing list
[email protected]
https://mail.python.org/mailman/listinfo/scipy-user
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.