Open main menu

Changes

Numpy linalg

539 bytes added, 09:58, 21 June 2014
x=np.arange(row*col).reshape((row, col))
print "shape is:", x.shape
print x
# Shape should end out in tuple.
shape = tuple([row, col - window + 1, window])
print "stride shape is:", shape
# Get strides
print "itemsize is", x_str
# Again, strides should be in tuple.# Strides tuble is a way to tell, how far is to next element.# Next element is first to next row in bytes = col * itemsize# and then how many bytes to next element in the row.
cut_strides = tuple(list(x_str) + [x_itz])
print "cut strides are", cut_strides
cut_strides_cal = tuple([col*x_itz] + [x_itz] + [x_itz])
print "Can be calculated as [col*x_itz] + [x_itz]:", cut_strides_cal
y = as_strided(x, shape=shape, strides=cut_strides)
 
print y
</source>
from numpy.lib.stride_tricks import as_strided
import numpy as np
NE, NS, NM, NO, ND, Row, Col = 1, 2, 2, 1, 2, 2, 2
mat = np.arange(1,NE*NS*NM*NO*ND*Row*Col+1).reshape(NE, NS, NM, NO, ND, Row, Col)
print "mat is:"
print mat
sz for ei in range(NE): for si in range(NS): for mi in range(NM): for oi in range(NO): for di in range(ND): print("ei:%i, si:%i, mi:%i, oi:%i, di:%i"%(ei, si, mi, oi, di)) print(mat[ei, si, mi, oi, di]) size = mat.itemsize
print "itemsize is:"
print szsize
strides = mat.strides
print "strides is"
print mat.strides print "height and width are"print h, w bh,bw = Row,Col shape = (h/bh, w/bw, bh, bw)print shape 
</source>