0
0

More than 1 year has passed since last update.

Numpyでnan以外のindexを検索する

Last updated at Posted at 2022-12-01

Numpyでnan以外のindexを取得したい

このような場合

import numpy as np
a = np.zeros(2, 2)
# a = [[0, 0], [0, 0]]
a[0, 0] = np.nan
# a = [[nan, 0], [0, 0]]

aのなかでnan以外のインデックスである[0, 0]が欲しい場合があります。

結論

np.argwhere(np.isnan(a))
# [0, 0]

非常にエレガントな手法ですね。
詳細は参考文献をどうぞ(英訳しただけ)

参考文献

0
0
2

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