Reputation: 889
Is it possible to find the parent array of a slice ie. the array that the slice is taken from? I would like to do this so I can add functionality to matplotlib plots which allows you to change which slice of an array you are viewing interactively in a plot. For instance, if I do this
plt.pcolormesh(myArray[0,:,:])
I would like to be able to run some code to change the plot to
plt.pcolormesh(myArray[1,:,:])
but to do that I need to know that myArray[0,:,:] is a slice of myArray.
Thanks Niall
Upvotes: 1
Views: 455
Reputation: 310049
With simple slices, you can look at the base
attribute:
a = np.arange(50)
b = a[10:20]
print (b.base is a)
However, I don't believe that this is guaranteed to work in all circumstances...(depending on contiguousness of a
, etc.)
Upvotes: 4