[ncl-talk] copy a vector (1D) to one of the dimensions of 2D array

Karin Meier-Fleischer meier-fleischer at dkrz.de
Thu Jan 31 03:13:52 MST 2019


Hi Greg,

you can use the conform function to copy the 1D-array to a 2D-array.

nx     = 8
ny     = 10

values = fspan(40.,452.,ny)

a = conform_dims((/ny,nx/),values,0)

Bye,
Karin

Am 31.01.19 um 10:04 schrieb Alessandra Giannini:
>
> onedtond!!!
>
> http://www.ncl.ucar.edu/Document/Functions/Built-in/onedtond.shtml
>
>
>
>> Alessandra Giannini
> IRI for Climate and Society - The Earth Institute at Columbia University
> P.O. Box 1000, Palisades NY 10964-8000, U.S.A.
>
> currently at:
> LMD - École Normale Supérieure
> 24, Rue Lhomond 75231 PARIS CEDEX 05, France
>
>> On Jan 30, 2019, at 5:28 PM, Greg Thompson <gthompsn at ucar.edu 
>> <mailto:gthompsn at ucar.edu>> wrote:
>>
>>
>> I am struggling (feeling dumb) that I cannot figure out how to write 
>> a one-line efficient solution to copy a 1D vector of latitude to all 
>> the columns of a 2D grid since the values (of latitude) are constant 
>> across my grid in the X-direction.
>>
>> So what I have is this
>> ny = 8
>> nx = 10
>> a = new( (/ny,nx/), float)
>> a = 0.
>> a(:, 0) = fspan(40., 42., ny)
>> do n = 1, nx-1
>>   a(:, n) = a(:,0)
>> end do
>>
>> but that DO-n loop is slow as nx grows large and I thought there was 
>> an elegant solution in NCL to treat this array manipulation.
>>
>> Any thoughts?
>> Thanks!!!
>>
>> Greg
>>
>> _______________________________________________
>> ncl-talk mailing list
>> ncl-talk at ucar.edu <mailto:ncl-talk at ucar.edu>
>> List instructions, subscriber options, unsubscribe:
>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
>
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at ucar.edu
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20190131/d054fa4d/attachment.html>


More information about the ncl-talk mailing list