I'm new to Python/numpy.
I'm trying to extend numpy.array to give it some functions that make it nice for representing images (e.g. convert to greyscale etc).
import numpy as np
import cv2
from support import *
import matplotlib.pyplot as plt
class Frame(np.array):
def __init__(self):
print "new frame"
f = Frame()
currently this gives me:
File "o.py", line 6, in <module>
class Frame(np.array):
TypeError: Error when calling the metaclass bases
cannot create 'builtin_function_or_method' instances
I don't understand why this is an issue for Python?
You want to be subclassing np.ndarray, not np.array, but it's a little more complicated than just swapping on out for the other in your example. It's probably worth taking a look at the documentation:
http://docs.scipy.org/doc/numpy/user/basics.subclassing.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With