numpy之meshgrid和flatten函数介绍

介绍meshgrid:

官方文档:https://docs.scipy.org/doc/numpy/reference/generated/numpy.meshgrid.html

文字解释:https://blog.csdn.net/sinat_29957455/article/details/78825945

图文并茂:https://blog.csdn.net/lllxxq141592654/article/details/81532855

介绍flatten:

https://blog.csdn.net/weixin_41803874/article/details/88371074

实验展示:

import numpy as np

# 注释显示了维度信息

x0 = np.arange(-2, 2.5, 0.25)  # (18,)

x1 = np.arange(-2, 2.5, 0.25)  # (18,)

X, Y = np.meshgrid(x0, x1)  # X=Y=(18, 18)

X = X.flatten()  # (324,),将18*18的二维矩阵压缩为324的一维矩阵

Y = Y.flatten()  # (324,)

np.array([X, Y])  # (2, 324)

你可能感兴趣的:(numpy之meshgrid和flatten函数介绍)