TypeError: super() takes at least 1 argument (0 given) error is specific to any python version?

Yes, the 0-argument syntax is specific to Python 3, see What’s New in Python 3.0 and PEP 3135 — New Super. In Python 2 and code that must be cross-version compatible, just stick to passing in the class object and instance explicitly. Yes, there are “backports” available that make a no-argument version of super() work … Read more

Is there a convenient way to apply a lookup table to a large array in numpy?

You can just use image to index into lut if lut is 1D. Here’s a starter on indexing in NumPy: http://www.scipy.org/Tentative_NumPy_Tutorial#head-864862d3f2bb4c32f04260fac61eb4ef34788c4c In [54]: lut = np.arange(10) * 10 In [55]: img = np.random.randint(0,9,size=(3,3)) In [56]: lut Out[56]: array([ 0, 10, 20, 30, 40, 50, 60, 70, 80, 90]) In [57]: img Out[57]: array([[2, 2, 4], … Read more

Why does ENcoding a string result in a DEcoding error (UnicodeDecodeError)?

“你好”.encode(‘utf-8′) encode converts a unicode object to a string object. But here you have invoked it on a string object (because you don’t have the u). So python has to convert the string to a unicode object first. So it does the equivalent of “你好”.decode().encode(‘utf-8′) But the decode fails because the string isn’t valid ascii. … Read more