From 18a12c0225ee28fca320632b80ed514c59eb8df9 Mon Sep 17 00:00:00 2001 From: Rob McMullen Date: Thu, 18 Feb 2016 10:17:21 -0800 Subject: [PATCH] Changed IndexedByteSegment to use numpy array as order so fancy indexing works in __getitem__ --- atrcopy/segments.py | 4 +++- atrcopy/utils.py | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/atrcopy/segments.py b/atrcopy/segments.py index 7e4d996..82d345f 100755 --- a/atrcopy/segments.py +++ b/atrcopy/segments.py @@ -1,6 +1,7 @@ import numpy as np from errors import * +from utils import to_numpy_list class SegmentSaver(object): @@ -264,7 +265,8 @@ class IndexedStyleWrapper(object): class IndexedByteSegment(DefaultSegment): def __init__(self, data, style, byte_order, **kwargs): - self.order = byte_order + # Convert to numpy list so fancy indexing works as argument to __getitem__ + self.order = to_numpy_list(byte_order) DefaultSegment.__init__(self, data, IndexedStyleWrapper(style, byte_order), 0, **kwargs) def __str__(self): diff --git a/atrcopy/utils.py b/atrcopy/utils.py index 44cdac9..6224653 100755 --- a/atrcopy/utils.py +++ b/atrcopy/utils.py @@ -9,3 +9,9 @@ def to_numpy(value): elif type(value) is types.StringType: return np.fromstring(value, dtype=np.uint8) raise TypeError("Can't convert to numpy data") + + +def to_numpy_list(value): + if type(value) is np.ndarray: + return value + return np.asarray(value, dtype=np.uint32)