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

前端 未结 2 938
礼貌的吻别
礼貌的吻别 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.

    0 讨论(0)
  • 2020-12-10 06:57

    It might be possible to compare where the indices live in memory using the ctypes property of the arrays. It might take some work, so you might want to step back and see if there is a different way of solving your problem.

    0 讨论(0)
提交回复
热议问题