When trying to replicating the code given here.
import numpy as np
n=4
m=5
a = np.arange(1,n*m+1).reshape(n,m)
sz = a.itemsize
h,w = a.shape
bh,bw = 2,2
shape = (h/bh, w/bw, bh, bw)
strides = sz*np.array([w*bh,bw,w,1])
blocks=np.lib.stride_tricks.as_strided(a, shape=shape, strides=strides)
print(blocks)
I got the following error message, what might be the reason?
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-3-0c3a23be3e7f> in <module>
12
13
---> 14 blocks=np.lib.stride_tricks.as_strided(a, shape=shape, strides=strides)
15 print(blocks)
~\AppData\Local\Continuum\anaconda3\envs\dropletflow\lib\site-packages\numpy\lib\stride_tricks.py in as_strided(x, shape, strides, subok, writeable)
100 interface['strides'] = tuple(strides)
101
--> 102 array = np.asarray(DummyArray(interface, base=x))
103 # The route via `__interface__` does not preserve structured
104 # dtypes. Since dtype should remain unchanged, we set it explicitly.
~\AppData\Local\Continuum\anaconda3\envs\dropletflow\lib\site-packages\numpy\core\numeric.py in asarray(a, dtype, order)
499
500 """
--> 501 return array(a, dtype, copy=False, order=order)
502
503
TypeError: 'float' object cannot be interpreted as an integer