0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Numpy形式でインデックスの行列を取得

Last updated at Posted at 2022-07-19

概要

画像処理なんかで行列要素の位置同士の演算をしたかった.
つまり以下のようなインデックスの行列が欲しかったので,その取得方法.
hoge.png

取得方法

追記: スマートなやり方をコメントしてくださったので,こちらがおすすめです.


np.array(np.meshgrid(*[np.arange(i) for i in (n_rows,n_columns)])).T

以上

参考:https://www.delftstack.com/ja/howto/numpy/python-numpy-combinations/#python-%E3%81%AE-numpy-meshgrid-%E9%96%A2%E6%95%B0%E3%81%A7-numpy-%E9%85%8D%E5%88%97%E3%81%AE%E7%B5%84%E3%81%BF%E5%90%88%E3%82%8F%E3%81%9B%E3%82%92%E5%8F%96%E5%BE%97%E3%81%99%E3%82%8B

0
0
1

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?