简体   繁体   English

python数组切片范围[:,:]

[英]python array slicing range with [:,:]

I'm testing a array slicing there is a problem. 我正在测试阵列切片存在问题。

I want to print (1,1)~(3,3) values, however python prints (1,1)~(2,2) why? 我想打印(1,1)~(3,3)值,但是python print (1,1)~(2,2)为什么?

import numpy as np
a = np.reshape(np.arange(25), (5,5))
print(a[1:3, 1:3])

Because 3 in your example is exclusive. 因为你的例子中的3是独占的。 Use 4 instead: 改用4:

print(a[1:4, 1:4])

When using Python's start:stop:step slice notation, start is inclusive, but stop is not. 当使用Python的start:stop:step slice表示法时,start是包含的,但是stop不是。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM