use ndarray() strides argument to construct subarray
previously this was done manually (and imperfectly)
This commit is contained in:
parent
aad1c737c3
commit
7c9107fa5d
@ -750,23 +750,15 @@ def subArray(data, offset, shape, stride):
|
||||
#data = data.flatten()
|
||||
data = data[offset:]
|
||||
shape = tuple(shape)
|
||||
stride = tuple(stride)
|
||||
extraShape = data.shape[1:]
|
||||
#print data.shape, offset, shape, stride
|
||||
for i in range(len(shape)):
|
||||
mask = (slice(None),) * i + (slice(None, shape[i] * stride[i]),)
|
||||
newShape = shape[:i+1]
|
||||
if i < len(shape)-1:
|
||||
newShape += (stride[i],)
|
||||
newShape += extraShape
|
||||
#print i, mask, newShape
|
||||
#print "start:\n", data.shape, data
|
||||
data = data[mask]
|
||||
#print "mask:\n", data.shape, data
|
||||
data = data.reshape(newShape)
|
||||
#print "reshape:\n", data.shape, data
|
||||
|
||||
strides = list(data.strides[::-1])
|
||||
itemsize = strides[-1]
|
||||
for s in stride[1::-1]:
|
||||
strides.append(itemsize * s)
|
||||
strides = tuple(strides[::-1])
|
||||
|
||||
return data
|
||||
return np.ndarray(buffer=data, shape=shape+extraShape, strides=strides, dtype=data.dtype)
|
||||
|
||||
|
||||
def transformToArray(tr):
|
||||
|
Loading…
Reference in New Issue
Block a user