一、 [::-1]
import numpy as np import numpy as np x = np.arange(1, 6) print("Original array:") print(x) print("Reverse array:") x = x[::-1] print(x) ''' Original array: [1 2 3 4 5] Reverse array: [5 4 3 2 1] '''
[::-1] :会将数组的元素逆向输出
二、 [::-1,::-1]
nums=np.array([[1,2,3,4], [5,6,7,8], [9,10,11,12], [13,14,15,16]]) print(nums[::-1,::-1]) ''' [[16 15 14 13] [12 11 10 9] [ 8 7 6 5] [ 4 3 2 1]] '''