# Re: convert array to scalar for subtraction?

From: Mary Haley <haley_at_nyahnyahspammersnyahnyah>
Date: Tue, 22 Sep 2009 06:41:09 -0600

On Mon, 21 Sep 2009 20:15:32 -0800
> Dear Jeanne,
>
> you can use a do loop to do the substraction
>
> example:
>
> diff= new((/199,64,128/), float) ; assume, x and y are float
>
> do t=0,198
> diff(t,:,:)=x(t,:,:)-y(0,:,:)
> end do
>
> thanks
>
> Debasish

Hi Jeanne and Debasish,

If you have enough memory, then you can also "conform" y to be
the same size as x, and do the difference without a loop:

y3d = conform(x,y,(/1,2/))
difft = x - y3d
delete(y3d)

The last argument of "conform" indicates which dimensions of "x"
that "y"'s dimensions are the same as.

Use "conform_dims" if you just have the dimension
sizes that you want to "conform" another array to.

--Mary

>
> Quoting Jeanne Thibeault <jeanne.thibeault_at_uconn.edu>:
>
>> Dear NCL,
>>
>> I would like to subtract one array from another: x-y
>>
>> x has dimensions [time | 199] x [lat | 64] x [lon | 128]
>> y has dimensions [time | 1] x [lat | 64] x [lon | 128]
>>
>> fatal:Minus: Dimension size, for dimension number 0, of operands
>>does
>> not match, can't continue
>>
>> I understand why I get the error. How can I convert the time
>> dimension of y to a scalar so that I can subtract it from each time
>> dimension of x? Or is there a better way?
>>
>> Thank you for your help.
>>
>> Jeanne
>>
>>
>>
>>
>>
>> _______________________________________________
>> ncl-talk mailing list
>> List instructions, subscriber options, unsubscribe:
>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>
>
>
>
> ----------------------------------------------------------------
> This message was sent using IMP, the Internet Messaging Program.
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Tue Sep 22 2009 - 06:41:09 MDT

This archive was generated by hypermail 2.2.0 : Thu Sep 24 2009 - 13:55:09 MDT