Skip to content

Commit 1adced1

Browse files
committed
create a subclass of numpy array overriding __repr__ method
1 parent 6c7b5f9 commit 1adced1

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

rmgpy/util.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import shutil
3434
import time
3535
from functools import wraps
36+
import numpy as np
3637

3738

3839
class Subject(object):
@@ -238,3 +239,13 @@ def as_list(item, default=None):
238239
return default
239240
else:
240241
return [item]
242+
243+
class np_list(np.ndarray):
244+
"""
245+
A subclass of numpy.ndarray which rendered as a list when printed.
246+
"""
247+
def __new__(cls, input_array):
248+
obj = np.asarray(input_array).view(cls)
249+
return obj
250+
def __repr__(self):
251+
return str(self.tolist())

0 commit comments

Comments
 (0)