[英]Why does printing a[0][:0:] give me a different answer than printing a[0][0] ? (Python multi-Dimensional array)
lets say I have array a where: 可以说我在哪里数组:
a = [[1.0,2.5,3.0],[2.0,5.0,3.0]]
why does doing print a[0][:0:]
output: 为什么要
print a[0][:0:]
输出:
[]
meanwhile doing print a[0][0]
outputs(the first Item in the first array within the array): [1.0]
同时
print a[0][0]
输出(数组中第一个数组中的第一项): [1.0]
I eventually want to take moving averages of multi-dimensional arrays. 我最终想要获取多维数组的移动平均值。 I want to make sure I understand the syntax first.
我想确保我先了解语法。
For the same reason that [1, 2, 3][0]
gives a different answer to [1, 2, 3][:0:]
. 出于同样的原因,
[1, 2, 3][0]
对[1, 2, 3][:0:]
给出了不同的答案。
[0]
will give the element at index 0, [:0:]
(or more simply [:0]
) will give all the elements from the start of the list to before the element at index 0 (which is en empty list of course). [0]
将给出索引为0的元素, [:0:]
(或更简单地为[:0]
)将给出从列表开头到索引0的元素之前的所有元素(该列表为空列表)。课程)。
[0]
is an index lookup, and [:0:]
is slice notation, so they are quite different things. [0]
是索引查找, [:0:]
是切片符号,因此它们是完全不同的东西。
This print a[0][0]
refers to the first element on 2d in the first element of 1d. 此
print a[0][0]
引用1d的第一个元素中2d上的第一个元素。
This print a[0][:0:]
refers to slice notation: 此
print a[0][:0:]
表示切片符号:
a[start:end] # items start through end-1
a[start:] # items start through the rest of the array
a[:end] # items from the beginning through end-1
a[:] # a copy of the whole array
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.