Numpy: views vs copy by slicing

前端 未结 3 1126
花落未央
花落未央 2020-12-05 14:44

When I am doing the slicing, an unexpected thing happened that seems the first to be view but the second is copy.

First

First slice of row, then slice of

3条回答
  •  执笔经年
    2020-12-05 15:44

    The accepted answer by John Zwinck is actually false (I just figured this out the hard way!). The problem in the question is a combination of doing "lvalue indexing" with numpy's fancy indexing. The following doc explains exactly this case

    https://scipy-cookbook.readthedocs.io/items/ViewsVsCopies.html

    in the section "But fancy indexing does seem to return views sometimes, doesn't it?"

提交回复
热议问题