Split a large numpy array into separate arrays with a list of grouped indices

后端 未结 1 1287
遇见更好的自我
遇见更好的自我 2021-01-16 19:03

Given 2 arrays: One for a master dataset, and the second as list of grouped indices that reference the master dataset. I\'m looking for the fastest to generate new arrays fr

相关标签:
1条回答
  • 2021-01-16 20:00

    You just have to reshape the index array:

    >>> result = POINT_CLOUD[INDICES.T]
    >>> np.allclose(result[0], LIST1)
    True
    >>> np.allclose(result[1], LIST2)
    True
    

    If you know the number of sub-arrays you can also unpack the list

    >>> result.shape
    (2, 1000000, 3)
    >>> L1, L2 = result
    >>> np.allclose(L1, LIST1)
    True
    >>> # etc
    

    This works for larger index groups. For the second example in your question:

    >>> INDICES = (np.random.rand(COUNT,4)*COUNT).astype(int)
    >>> SPLIT = POINT_CLOUD[INDICES.T]
    >>> SPLIT.shape
    (4, 1000000, 3)
    >>> 
    
    0 讨论(0)
自定义标题
段落格式
字体
字号
代码语言
提交回复
热议问题