Nicolas P. Rougier
2016-11-03 18:29:10 UTC
Hi all,
Given an array V that is a view of a base B, I was wondering if it is possible
to find a (string) index such that `V = B[index]`
For example:
```
B = np.arange(8*8).reshape(8,8)
V = B[::2,::2]
index = find_view(B,V)
print(index)
"::2,::2"
print(np.allclose(V, eval("B[%s]" % index)))
True
```
I wrote a solution at https://gist.github.com/rougier/b8c2256434b3a4a4271260cd4cc6cbc7
(not very thoroughly tested) but maybe there are better ways to do that (like a magic numpy call ?)
(no use-case at all, only for teaching)
Nicolas
Given an array V that is a view of a base B, I was wondering if it is possible
to find a (string) index such that `V = B[index]`
For example:
```
B = np.arange(8*8).reshape(8,8)
V = B[::2,::2]
index = find_view(B,V)
print(index)
"::2,::2"
print(np.allclose(V, eval("B[%s]" % index)))
True
```
I wrote a solution at https://gist.github.com/rougier/b8c2256434b3a4a4271260cd4cc6cbc7
(not very thoroughly tested) but maybe there are better ways to do that (like a magic numpy call ?)
(no use-case at all, only for teaching)
Nicolas