Method: subMatrix
get subMatrix of current Matrix, in ranges point:point+width. Type is the same type as the current matrix
guid:
|
www.ccpn.ac.uk_Fogh_2010-05-12-17:36:49_00002
|
OpType:
|
other
|
OpSubType:
|
None
|
isQuery:
|
True
|
isAbstract:
|
False
|
Scope:
|
instance_level
|
Code:
|
# read in data
ndim = self.ndim
data = self.__dict__['data']
strides = self.strides
shape = self.shape
# set widths - padding to dimension sizes.
ll = list(shape)
if widths is not None:
ll[:len(widths)] = widths
widths = ll
#set point - padding with zero
ll = ndim * [0]
if point is not None:
ll[:len(point)] = point
point = ll
# adjust widths for cases where width==0, and set new shape.
newshape = []
for ii,width in enumerate(widths):
if width:
newshape.append(width) # use only dims with non-zero widths
else:
widths[ii] = 1 # replace width 0 with width 1 for further processing
# find start indices for stretches of data used
indices = [0]
for dim,stride in enumerate(strides[:-1]):
offset = point[dim] * stride
width = widths[dim]
ll = []
for index in indices:
newindex = index + offset
for dummy in range(width):
ll.append(newindex)
newindex += stride
indices = ll
# get actual data and create new data array
width = widths[-1]
newdata = [None] * (width * len(indices))
start = 0
for index in indices:
end = start + width
newdata[start:end] = data[index:index+width]
start = end
# create subMatrix object
result = self.__class__(shape=newshape, data=newdata)
|
|