how do I check that two slices of numpy arrays are the same (or overlapping)?

前端 未结 2 945
礼貌的吻别
礼貌的吻别 2020-12-10 06:10

I would like to check if two ndarrays are overlapping views of the same underlying ndarray.

To check that two slices are exactly the same, I can do something like:

2条回答
  •  轮回少年
    2020-12-10 06:55

    numpy.may_share_memory() is the best heuristic that we have at the moment. It is conservatively heuristic; it may give you false positives, but it will not give you false negatives. I think there might be ways to improve the heuristic to be 100% correct. If they pan out, they will be folded into that function, so that's the best way forward.

提交回复
热议问题