11
7

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 5 years have passed since last update.

Numpyで多次元配列を作る方法

Last updated at Posted at 2018-06-07

XY平面上で格子点をとりたいときに。x=np.linspace...,y=linspce...とかやってもいいけど変数増えてめんどくさい時に
(x,y)でまとめられます。
np.mgrid[x開始点:x終点:y交差,y開始点:y終点:y公差]
で出来ます。終点は含みません。
公差のところを項数にもできます。このとき公差ではなく、項数であることを示すために、項数のあとにjをつける必要があります。

np.mgrid[x開始点:x終点:x項数j,y開始点:y終点:y項数j]

In [43]: np.mgrid[1:5:0.5,0:5:0.5]
Out[43]:
array([[[1. , 1. , 1. , 1. , 1. , 1. , 1. , 1. , 1. , 1. ],
        [1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5],
        [2. , 2. , 2. , 2. , 2. , 2. , 2. , 2. , 2. , 2. ],
        [2.5, 2.5, 2.5, 2.5, 2.5, 2.5, 2.5, 2.5, 2.5, 2.5],
        [3. , 3. , 3. , 3. , 3. , 3. , 3. , 3. , 3. , 3. ],
        [3.5, 3.5, 3.5, 3.5, 3.5, 3.5, 3.5, 3.5, 3.5, 3.5],
        [4. , 4. , 4. , 4. , 4. , 4. , 4. , 4. , 4. , 4. ],
        [4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.5]],

       [[0. , 0.5, 1. , 1.5, 2. , 2.5, 3. , 3.5, 4. , 4.5],
        [0. , 0.5, 1. , 1.5, 2. , 2.5, 3. , 3.5, 4. , 4.5],
        [0. , 0.5, 1. , 1.5, 2. , 2.5, 3. , 3.5, 4. , 4.5],
        [0. , 0.5, 1. , 1.5, 2. , 2.5, 3. , 3.5, 4. , 4.5],
        [0. , 0.5, 1. , 1.5, 2. , 2.5, 3. , 3.5, 4. , 4.5],
        [0. , 0.5, 1. , 1.5, 2. , 2.5, 3. , 3.5, 4. , 4.5],
        [0. , 0.5, 1. , 1.5, 2. , 2.5, 3. , 3.5, 4. , 4.5],
        [0. , 0.5, 1. , 1.5, 2. , 2.5, 3. , 3.5, 4. , 4.5]]])
11
7
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
11
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?