How to use numpy's "mgrid" function



Python
library
pip

MeCab

Common
class

pickle

read/readline

numpy
asfarray

digitize

expit

linalg.solve

meshgrid

mgrid

ndmin

pad

poly1d

polyfit

prod

shape

matplotlib
figure

pcolormesh

scatter

pytorch
BCELoss, MSELoss

device

Embedding

TensorDataset, Dataloader

RNN, LSTM
scikit-learn
SVC

GaussianNB

scipy
interpolate
tkinter
postscript

image display

frame, grid

Crop Image

other
linear interpolation

Hysteresis switch

Square/Triangle wave

OpenAI gym
CartPole-v0

By purpose
1 of K Coding


Release date:2022/6/20         

In Japanese


■Description of the mgrid function

Generates a grid array.

■Specific example using mgrid function

import numpy as np

np.mgrid[0:2:0.5 , 0:3:1]
# X-axis: 0 to the second axis in 0.5 increments. Y-axis: 0 to the 3rd axis in 1 increments.

  ⇒ array([[[0. , 0. , 0. ],
      [0.5, 0.5, 0.5],
      [1. , 1. , 1. ],
      [1.5, 1.5, 1.5]],

      [[0. , 1. , 2. ],
      [0. , 1. , 2. ],
      [0. , 1. , 2. ],
      [0. , 1. , 2. ]]])


<Difference between mgrid function and meshgrid function>

A function similar to mgrid is the meshgrid function. The difference is that mgrid can only create an array with equal intervals by deciding the start point and end point, but meshgrid can create an array with arbitrary intervals. Instead, mgrid is simple to write.

It is also important to note that the definitions of the X-axis and Y-axis are different as follows.









List of related articles



Python
library
pip

MeCab

Common
class

pickle

read/readline

numpy
asfarray

digitize

expit

linalg.solve

meshgrid

mgrid

ndmin

pad

poly1d

polyfit

prod

shape

matplotlib
figure

pcolormesh

scatter

pytorch
BCELoss, MSELoss

device

Embedding

TensorDataset, Dataloader

RNN, LSTM
scikit-learn
SVC

GaussianNB

scipy
interpolate
tkinter
postscript

image display

frame, grid

Crop Image

other
linear interpolation

Hysteresis switch

Square/Triangle wave

OpenAI gym
CartPole-v0

By purpose
1 of K Coding