Re: Removing Array Values [message #78581] |
Wed, 07 December 2011 18:35 |
Oana Coman
Messages: 27 Registered: December 2011
|
Junior Member |
|
|
On Dec 7, 9:12 pm, Oana Coman <ecatc...@gmail.com> wrote:
> Hi Guys!
> I'm trying to make a sparse matrix where I have 1 1 0 1 1 0 etc as the
> off-diagonal entries
> So I want something like
> i= 1 2 4 5 7 8 ...etc
> j= 0 1 3 4 6 7 ....etc
> val = 1 1 1 1 1 1
> so when I put this in a 9X9 matrix it will go across the diagonal but
> will leave a 0 after every two 1 values
>
> Basically, all I need to do for this is create two arrays...one that
> skips every multiple of 3n, and one that skips every multiple of
> (3n-1). Is there some way to remove all of these 3n, and 3n-1 array
> values? I am having a really difficult time finding anything online
> that's relatively helpful
>
> Thanks!
Would probably be helpful if I put in my code:
N=3
negOnei=indgen(N^2-1)+1 ;This is where I want to skip multiples of
3n
negOnej=indgen(N^2-1) ;This is where I want to skip multiples of
3n-1
negOne = make_array(1,N^2-1, /INTEGER, VALUE=-1); ;here, it should
b N^2-N but I made it N^2-1 to have the code run. Because I want a 0
every two -1 values, but I don't want that 0 stored.
si=indgen(N^2-1)
sj=indgen(N^2-1)
s = 4*make_array(1,N^2-1, /INTEGER, VALUE=1)
onei=indgen(N^2-N)+N
onej=indgen(N^2-N)
one = make_array(1,N^2-N, /INTEGER, VALUE=1);
i=[si,onei,onej, negOnei, negOnej]
j=[sj,onej,onei, negOnej, negOnei]
vals=[[s],[one],[one], [negOne], [negOne]]
sparse=sprsin(i,j,vals,N^2)
|
|
|