0
0

【xarray】マスクを適用する (where)

Last updated at Posted at 2023-09-11

この記事では、以下のライブラリを用いる。

import xarray as xr
import numpy as np

マスクを適用する

DataArrayのメソッドwhere()を利用する。

次のDataArrayを例として説明する。

array = xr.DataArray([1, 2, 3], dims='x')
array

image.png

mask = xr.DataArray([True, False, True], dims='x')
mask

image.png

方法①

where()の引数にmaskを指定する。maskFalseの場所にnanが入る。

array.where(mask)

image.png

方法②

ビット反転演算子~を利用すると、maskTrueの場所にnanが入る。

array.where(~mask)

image.png

マスクを取得する

マスクを取得する方法については以下の記事を参照。

公式ドキュメント

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0