| Re: What are the rules for automatic removal of singleton dimensions, and can I have a way of disabling them, please? [message #82632 is a reply to message #82553] |
Thu, 27 December 2012 15:06   |
tom.grydeland
Messages: 51 Registered: September 2012
|
Member |
|
|
On Thursday, December 27, 2012 12:12:40 AM UTC+1, Mats Löfdahl wrote:
> Den onsdagen den 26:e december 2012 kl. 15:12:35 UTC+1 skrev Tom Grydeland:
>> In my mind, the fix is to make things behave _less_ arbitrarily, not _more_ so.
> So then we agree.
Good!
>> That solution is worse than the problem, IMO. How many other functions will I have to replace?
> How would I know? Total() is the only one you mentioned...
Yes -- I believe in making my posted examples as succinct as possible.
You pointed out something of which I wasn't aware -- that adding an extra [ ... , 0] index does not raise an exception or change the returned values. This is valuable information, but not something I would base my code on. In my mind, it means indexing has one special case with erratic behavior. Before I start modifying (parts of) the IDL standard library to also behave erratically (and then have to keep track of which parts are so modified), I would try almost any other solution which mean that my array has the number of dimensions I want before I start:
pro atleast_n_dim, a, n
adim = size(a, /dimensions)
if n_elements(adim) eq n then return
adim = [adim, 1+intarr(n-n_elements(adim))]
a = reform(a, adim, /overwrite)
return
end
--T
|
|
|
|