python [::-1] [::-1,::-1]

简介: python [::-1] [::-1,::-1]

一、 [::-1]



a34cc83b8f9547a5b7933279b566d25f.png

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] :会将数组的元素逆向输出


e1c8b5157a47450c86dda5050c66aa88.png


二、 [::-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]]
'''

acbe50f7166341b299b446da9f2488e6.png


相关文章
|
9月前
|
5G Python
Python 的十万个为什么?
Python 的十万个为什么?
39 3
|
6月前
|
索引 Python
干货!20个Python使用小技巧
干货!20个Python使用小技巧
81 0
|
8月前
|
Python
Python一些实用小技巧
Python一些实用小技巧
28 0
|
9月前
|
Python
Python小灰灰
Python小灰灰
88 0
|
9月前
|
Python
python作业题
python作业题
|
9月前
|
XML Shell 数据库
V1.0.0 Python可以做什么
V1.0.0 Python可以做什么
47 0
|
机器学习/深度学习 并行计算 数据挖掘
【python是什么】
【python是什么】
113 0
|
机器学习/深度学习 XML 存储
认识 Python
人生苦短,我用 Python —— Life is short, you need Python
168 0
|
Python
Python中的“in”和“not in”
Python中的“in”和“not in”, “in”是用来检查字典中是否包含指定的键, “not in”是检查字典中是否不包含指定的键,这两个正好相反。
609 0
Python中的“in”和“not in”