Python基本功

如何获取一个变量的类型?

type(noisy_movies.shape)

如何获取tuple的形状?

noisy_movies.shape

如何拿到tuple形状的第一列?

noisy_movies.shape[0]

如何plot出来一张2D数组(像matlab中的imshow)?

from matplotlib import pyplot as plt

# Let's look at the results.
plt.figure(figsize=(16,8))
plt.subplot(1,2,1)
plt.imshow(tmpNoiseImage,cmap="magma")
plt.title('Input');
plt.subplot(1,2,2)
plt.imshow(tmpShiftedImage,cmap="magma")
plt.title('Prediction');

如何保存一张2D数组作为图片(像matlab中的imwrite)?

dataPath = 'd:/aa/bb/'
plt.savefig(dataPath+'%i_animate.png' % (i + 1))

如何创建任意形状的np数组(eg,(582, 512, 512, 1)   )?

tmpSourceImagesArray = np.zeros((len(self.LabelImages),512, 512,1),dtype = np.float32)

如何获取一个矩阵中的最大最小值?

a.max()

如何进行类型转换(uint16->float32)

c = c.astype(np.float32)

 

posted @ 2019-10-06 12:30  bH1pJ  阅读(27)  评论(0编辑  收藏  举报