我在文档中找不到任何内容,但它被用于我在学校上课的一些入门代码中。根据下面的测试,它似乎颠倒了 numpy 数组的维度顺序。
pic = np.ones((3,4,5))
print(pic.shape,"\n", pic)
#new_shape is the reverse of pic.shape
new_shape = pic.shape[::-1]
print(new_shape)
这输出:
(3, 4, 5)
[[[1. 1. 1. 1. 1.]
[1. 1. 1. 1. 1.]
[1. 1. 1. 1. 1.]
[1. 1. 1. 1. 1.]]
[[1. 1. 1. 1. 1.]
[1. 1. 1. 1. 1.]
[1. 1. 1. 1. 1.]
[1. 1. 1. 1. 1.]]
[[1. 1. 1. 1. 1.]
[1. 1. 1. 1. 1.]
[1. 1. 1. 1. 1.]
[1. 1. 1. 1. 1.]]]
(5, 4, 3)
在入门代码中,它是这样使用的:
res_img = cv2.resize(img, sub_img.shape[::-1])
启动代码中还植入了一些其他技巧(我猜想是为了向我们展示它们的存在)。这是另一个例子:
channels = blue, green, red = np.moveaxis(color_img, 2, 0) #move channels to pos 0
将np.moveaxis()通道移动到第一个暗淡位置,但通过 Python 多重分配同时分配给蓝色、绿色和红色?当我查找多项作业时,我只看到了类似var1, var2 = 1, 2. 还np.moveaxis()返回一个具有新形状的数组,所以我必须扩展我的想象力来假设第一个轴可以分配给变量。它是否正确?
我的导师刚刚回答说进行np.split()了拆分,但文档没有说明在调用时隐式调用它的任何内容np.moveaxis()。
有谁知道到底发生了什么?