Skip to content

Instantly share code, notes, and snippets.

@hgrecco
Created August 21, 2013 01:28
Show Gist options
  • Save hgrecco/6289396 to your computer and use it in GitHub Desktop.
Save hgrecco/6289396 to your computer and use it in GitHub Desktop.
Wrapping a ndarray
import numpy as np
class C(object):
def __init__(self, value):
self.value = value
def __getattr__(self, name):
return getattr(self.value, name)
c = C(np.arange(1, 10))
an = np.asanyarray(c)
ar = np.asarray(c)
print(type(c), c)
print(type(an), an)
print(type(ar), ar)
@hgrecco
Copy link
Author

hgrecco commented Aug 21, 2013

The output in NumPy 1.7.1

(<class '__main__.C'>, <__main__.C object at 0x10135f090>)
(<type 'numpy.ndarray'>, array([1, 2, 3, 4, 5, 6, 7, 8, 9]))
(<type 'numpy.ndarray'>, array([1, 2, 3, 4, 5, 6, 7, 8, 9]))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment