Re: replacing blocks in an array with other array values? [message #78817] |
Sun, 25 December 2011 20:42 |
Ecaterina Coman
Messages: 3 Registered: December 2011
|
Junior Member |
|
|
Thanks guys!
Those were both helpful, as I got to test them out and see I wasn't
crazy and stuff IS supposed to work the way I thought it did!
My issues was actually that my "b" was float and my "a" was type int.
Amazing how something so simple can cause you to sit there scratching
ur head at a loss for hours haha
|
|
|
Re: replacing blocks in an array with other array values? [message #78818 is a reply to message #78817] |
Sun, 25 December 2011 15:44  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
Ecaterina Coman writes:
> I have a 4*4 array, for example, and i want to replace the center 2*2
> block of an array with the values in another array
>
> lets say A is 4*4
> and B is 2*2
> I tried doing A[1:2,1:2]=B but it doesn't change anything in A
> on the other hand, when I put A[1:2,1:2]=some scalar, it replaces the
> whole block by that scalar and works
>
> i feel like there should be a simple way to do this but cannot figure
> it out
You will have to specify the lower-left corner of the
array, like this:
IDL> a = indgen(4, 4)
IDL> b = indgen(2,2)+20
IDL> a[1,1] = b
IDL> print, a
0 1 2 3
4 20 21 7
8 22 23 11
12 13 14 15
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
|
|
|
Re: replacing blocks in an array with other array values? [message #78819 is a reply to message #78818] |
Sun, 25 December 2011 15:43  |
penteado
Messages: 866 Registered: February 2018
|
Senior Member Administrator |
|
|
On Dec 25, 7:11 pm, Ecaterina Coman <ecatc...@umbc.edu> wrote:
> hi guys,
> I have a 4*4 array, for example, and i want to replace the center 2*2
> block of an array with the values in another array
>
> lets say A is 4*4
> and B is 2*2
> I tried doing A[1:2,1:2]=B but it doesn't change anything in A
Really?
IDL> a=bindgen(4,4)
IDL> b=100+bindgen(2,2)
IDL> print,a
0 1 2 3
4 5 6 7
8 9 10 11
12 13 14 15
IDL> print,b
100 101
102 103
IDL> a[1:2,1:2]=b
IDL> print,a
0 1 2 3
4 100 101 7
8 102 103 11
12 13 14 15
|
|
|