简体   繁体   中英

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). 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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