[ncl-talk] Fill Values in NCL and Python

Karin Meier-Fleischer meier-fleischer at dkrz.de
Wed Feb 28 08:02:18 MST 2024


Hi Barry,

the following two Python examples demonstrate how to set values in a 
NumPy and an Xarray array to NaN using a condition.

arr = np.arange(0., 10.)
arr[arr >= 7.] = np.nan
print(arr)

-----> output: [ 0. 1. 2. 3. 4. 5. 6. nan nan nan]

xarr = xr.DataArray(np.arange(10))
xarr = xarr.where(xarr < 7, np.nan)
print(xarr.values)

-----> output: [ 0. 1. 2. 3. 4. 5. 6. nan nan nan]

Regards,
Karin

Am 28.02.24 um 15:10 schrieb Barry Lynn via ncl-talk:
> Hi:
>
> I know how to change an array value to fillvalue in NCL using a where 
> statement.
>
> How do I do the same in python, please?
>
> Barry
> -- 
>
> Barry H. Lynn, Ph.D
> Senior Scientist, Lecturer,
> The Institute of Earth Sciences,
> The Hebrew University of Jerusalem,
> Givat Ram, Jerusalem 91904, Israel
> Tel: 972 547 231 170
> Fax: (972)-25662581
>
> Weather It Is, LTD
> Weather and Climate Focus
> https://weather-it-is.com <http://weather-it-is.com>
> Jerusalem, Israel
> Local: 02 930 9525
> Cell: 054 7 231 170
> Int-IS: x972 2 930 9525
>
>
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at mailman.ucar.edu
> List instructions, subscriber options, unsubscribe:
> https://mailman.ucar.edu/mailman/listinfo/ncl-talk
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.ucar.edu/pipermail/ncl-talk/attachments/20240228/be610973/attachment.htm>


More information about the ncl-talk mailing list