How to return a view of several columns in numpy structured array

后端 未结 5 2003
既然无缘
既然无缘 2021-01-31 18:13

I can see several columns (fields) at once in a numpy structured array by indexing with a list of the field names, for example

import n         


        
5条回答
  •  北荒
    北荒 (楼主)
    2021-01-31 18:24

    Building on @HYRY's answer, you could also use ndarray's method getfield:

    def fields_view(array, fields):
        return array.getfield(numpy.dtype(
            {name: array.dtype.fields[name] for name in fields}
        ))
    

提交回复
热议问题