From 7c9107fa5d9954d2f59bcabf523dc2fdb77eee34 Mon Sep 17 00:00:00 2001 From: Luke Campagnola Date: Fri, 29 Sep 2017 08:45:33 -0700 Subject: [PATCH] use ndarray() strides argument to construct subarray previously this was done manually (and imperfectly) --- pyqtgraph/functions.py | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/pyqtgraph/functions.py b/pyqtgraph/functions.py index 261727cb..b38888fe 100644 --- a/pyqtgraph/functions.py +++ b/pyqtgraph/functions.py @@ -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):