[英]How to do array slicing with a python sequence
I am using numpy.genfromtxt
and the usecols
parameter allows filtering out columns (by non-inclusion). 我正在使用numpy.genfromtxt
,并且usecols
参数允许过滤出列(不包括在内)。 For a lengthy list of columns it is not ideal to explicitly mention every single one - given that only one column need not be included. 对于冗长的列列表,显式地提及每一个列都不是理想的-考虑到只需要包含一列。
If the sequence were instead a list then we could use 如果序列是列表,那么我们可以使用
usecols=[1:]
However that is not possible for a sequence - which afaict needs to be like 但是,这对于序列是不可能的-该序列需要像
usecols=(1,2,3,4, .. and many many more ..)
Here is the specific invocation that is being attempted: 这是尝试的特定调用:
data = np.genfromtxt(path, delimiter=',',skip_header= 1,usecols=[1:])
That does not compile due to the invalid attempt to use the slicing syntax on the sequence. 由于无效尝试在序列上使用切片语法,因此无法编译。 is there any alternative supported by sequences? 序列是否有其他选择?
生成类似于[i for i in range(n)]
的完整列列表,然后使用remove()
删除所需的元素,并将此过滤后的列表传递给usecols
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.