当前位置:网站首页>Numpy multidimensional array transpose transpose

Numpy multidimensional array transpose transpose

2022-06-13 01:39:00 Under the starry sky 0516

How to convert multidimensional numpy The axis transformation position of the array , For example, a 3x3x3 Array of , Change the position of the data of the first axis and the data of the third axis , First, let's take a look at one 3x3x3 The arrangement of arrays before replacement :

num = 3
images = np.arange(1, num**3+1).reshape(num, num, num)
for dim in range(0, num):
	plt.subplot(1, 3, dim+1)
	image = images[dim, :, :]
	plt.imshow(image)
	for i in range(image.shape[0]):
		for j in range(image.shape[1]):
			text = plt.text(j, i, int(image[i, j]), ha = "center", va = "center", color="r")
	plt.xticks([]); plt.yticks([])
	plt.show()

Output pictures :
 Insert picture description here
If the first and third shafts are replaced , You can use the following program :

images = images.transpose((1, 0, 2))

give the result as follows : Insert picture description here

原网站

版权声明
本文为[Under the starry sky 0516]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/164/202206130137385277.html