Changes

Jump to navigation Jump to search

Numpy linalg

623 bytes added, 09:48, 21 June 2014
http://wiki.scipy.org/Cookbook/SegmentAxis
Simple, with window 3
<source lang="python">
row, col = 3, 5
 
x=np.arange(row*col).reshape((row, col))
print x
 
window = 3
# Shape should end out in tuple.
shape = tuple([row, col - window + 1, window])
print "shape is:", shape
 
# Get strides
x_str = x.strides
print "strides is", x_str
 
# Get itemsize, Length of one array element in bytes. Depends on dtype. float64=8, complex128=16.
x_itz = x.itemsize
print "itemsize is", x_str
 
# Again, strides should be in tuple
cut_strides = tuple(list(x_str) + [x_itz])
print "cut strides are", cut_strides
 
y = as_strided(x, shape=shape, strides=cut_strides)
</source>
 
And then
<source lang="python">

Navigation menu