You can't have two values at the same row and column, which is what the first two lines of this output would indicate:
[1, 1] = 1.0 [1, 1] = 1.0 [2, 2] = 1.0 Since the indices (1,1) appear twice the associated values are added, giving 2.0. On Tue, Feb 23, 2016 at 5:03 PM, Yankai Cao <[email protected]> wrote: > I am new to Julia. I have 2 questions about constructting sparse matrix > from arrays. > > 1. > I=[1;1;2] > J=[1;1;2] > V=[1.0;1.0;1.0] > Mat=sparse(I,J,V,2,2) > > According to the Julia guide "If the combine function is not supplied, > duplicates are added by default." I expect Mat to be > [ 1, 1] =1.0 > [ 1, 1] = 1.0 > [2, 2] = 1.0 > > however, what I get is > [1,1]=2 > [2,2]=1 > > So what is the default behavior without combine function? How do I specify > the combine function? There is no instructions about it right now. > > 2. when i change V=[1.0;0.0;0.0]. I expected > [ 1, 1] = 1.0 > [2, 2] = 0 > > what I get is > [1,1]=1 > > How can I let julia to combine elements only according to the indexes I, J > ? How to keep those elements with value 0 ? > > > Thanks in advance. > > > Yankai > > > > >
