Skip to content

Commit

Permalink
use ndarray() strides argument to construct subarray
Browse files Browse the repository at this point in the history
previously this was done manually (and imperfectly)
  • Loading branch information
campagnola committed Sep 29, 2017
1 parent aad1c73 commit 7c9107f
Showing 1 changed file with 7 additions and 15 deletions.
22 changes: 7 additions & 15 deletions pyqtgraph/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 7c9107f

Please sign in to comment.