X
PrevPrev Go to previous topic
NextNext Go to next topic
Last Post 02 Jul 2007 05:12 AM by  anon
Strange behaviour when multiplying an array by a float
 1 Replies
Sort:
You are not authorized to post a reply.
Author Messages

anon



New Member


Posts:
New Member


--
02 Jul 2007 05:12 AM
    Hi all, I'm attempting to run the following code: temp=where(moddata ne 0 or msgdata ne 0,count) result=regress(moddata[temp],msgdata[temp],CONST=const) print,result if count ne 0 then outdata[temp]=msgdata[temp]*float(result) In this code moddata,msgdata and outdata are all fltarr(2766,2631). Moddata and Msgdata are loaded from tiff files (via ENVI) and outdata is saved to another tiff file. Now, the problem is - when I open up the output tiff all my data is set equal to zero! In other words, msgdata[temp]*float(result)=0 Anyone know why this is the case? I know that the actual value for result is okay (if I manually type the value in then I get the correct output), but if I use the variable I get zero. My thinking is that it's some kind of type conversion problem, but as everything is a floating point value I'm not quite sure what's happening. Any ideas will be greatly appreciated! Thanks, Simon.

    Deleted User



    New Member


    Posts:
    New Member


    --
    02 Jul 2007 05:12 AM
    If 'msgdata' and 'moddata' are FLOATs, then 'result' must be a FLOAT and there should be no FLOAT( ) conversion call necessary in this example. That is probably besides the point for your question, however. Perhaps if you called "help, result" instead of "print, result", the root of the problem would be clearer. REGRESS always returns an array. I am guessing that in your example, it is returning a 1-element array. In IDL a 1-element array multiplied by a multi-element array of any dimension will return a 1-element result - it will be the product of the first element of the multi-element array times the value of the 1-element array, one single value. That is very different from the result one gets if one multiplies an array by a scalar. When a programmer "manually types a value" he/she is usually typing a scalar. That would explain the differing results you are getting from your variable and your manual typing. Now compare the result of: outdata[temp] = msgdata[temp] * result to the result of: outdata[temp] = msgdata[temp] * result[0] ; The subscript converts this to a scalar I bet that fixes at least part of your problem. You may have another problem here, though, as well. What is the meaning of this? temp = where(moddata ne 0 or msgdata ne 0, count) 'temp' in this case ends up with subscripts valid for 'moddata' mixed with subscripts valid for 'msgdata'. Is this really what you want. In the example you showed above, I suspect that your call: outdata[temp]=msgdata[temp]*float(result) had a subscript in the location temp[0] that was non-zero in 'moddata', but was zero in 'msgdata'. That is why you ended up with all those 0 values in your 'outdata'. James Jones
    You are not authorized to post a reply.