Manipulation des strides d'array de numpy¶
In [1]:
import numpy as np
In [2]:
a = np.arange(20)
In [3]:
a
Out[3]:
In [4]:
a = a.reshape((5,4), order='F')
In [5]:
a
Out[5]:
In [6]:
from numpy.lib.stride_tricks import as_strided
In [7]:
a.strides
Out[7]:
In [8]:
a.shape
Out[8]:
In [9]:
b = as_strided(a, strides=(8, 16), shape=(2, 10))
In [10]:
b
Out[10]:
In [11]:
c = as_strided(a, strides=(8, 16), shape=(4, 9))
In [12]:
c
Out[12]:
In [13]:
id(a), id(b), id(c)
Out[13]:
In [14]:
d = as_strided(a, strides=(8, 16), shape=(5, (20-5)//2+1))
In [15]:
d
Out[15]:
In [33]:
b = as_strided(a, strides=(16, 8, 80), shape=(10, 2, 2))
In [34]:
b
Out[34]:
In [18]:
a.__array_interface__['data'][0]
Out[18]: