Dimensional confusion [message #82116] |
Tue, 20 November 2012 05:54 |
Helder Marchetto
Messages: 520 Registered: November 2011
|
Senior Member |
|
|
Hi,
I was just trying to add an element to an array and got a bit confused with the dimensions. Therefore I wrote a post to ask for a solution and then feeling that the answer to the question couldn't be hard, I kept fighting for a solution until I got one... Therefore I'm posting question and answer. Now I'm maybe less confused about dimensions, but for sure more confused about the use of a group!
Say I construct an array as:
a = indgen(4,2)
and I want to add the element [0,0] at the end in order to have a 5x2 array.
The first solution I got was this (transpose-overdose):
b = transpose([[transpose([a])],[0,0]])
Then I tried to reduce the number of transpose and I got to this:
b = [[a],transpose([0,0])]
And then I told myself that there has to be a way to avoid that transpose function... and this was my solution:
b = [a,[[0],[0]]]
All these lead to the same answer:
IDL> help, a, b
A FLOAT = Array[4, 2]
B FLOAT = Array[5, 2]
Now the world seems fine again and I lost another half an hour to reinvent the wheel.
I thank groups.google for allowing some space to write some text and to think about what I just wrote.
Helder
PS: I hope some-where some-one finds this useful (also for teaching purposes as "what not to do")
|
|
|