Numpy: equivalent to numpy.roll, but only for data visualization

Is there a way to execute a roll over an array, but instead of having a copy of data that has only visualization?

An example can be made clear: given b deployed version of a ...

 >>> a = np.random.randint(0, 10, (3, 3)) >>> a array([[6, 7, 4], [5, 4, 8], [1, 3, 4]]) >>> b = np.roll(a, 1, axis=0) >>> b array([[1, 3, 4], [6, 7, 4], [5, 4, 8]]) 

... if I perform an assignment in an array b ...

 >>> b[2,2] = 99 >>> b array([[ 1, 3, 4], [ 6, 7, 4], [ 5, 4, 99]]) 

... the contents of a will not change ...

 >>> a array([[6, 7, 4], [5, 4, 8], [1, 3, 4]]) 

... on the contrary, I would like to have:

 >>> a array([[6, 7, 4], [5, 4, 99], # observe as `8` has been changed here too! [1, 3, 4]]) 

Thank you in advance for your time and knowledge!

+7
source share
1 answer

This is not possible, sorry. An inverted array cannot be described by another set of strides , which is necessary to view NumPy.

+9
source

All Articles