numpy.shape的用法辨析shape[1:],shape[:-1]的区别

数组a的形状
a.shape为(400,500,3)


import numpy
a = numpy.random.rand(400,500,3)
print(a.shape)
print(a.shape[1])
print(a.shape[1:])
print(a.shape[1::])
print(a.shape[:-1])
print(a.shape[:])
print(a.shape[::])
print(a.shape[::-1])
print(a.shape[1::-1])

输出

(400, 500, 3)
500
(500, 3)
(500, 3)
(400, 500)
(400, 500, 3)
(400, 500, 3)
(3, 500, 400)
(500, 400)

pytorch有类似的用法

你可能感兴趣的:(numpy,python)