Alternative to scipy.misc.imresize()
You can lookup the documentation and the source code of the deprecated function. In short, using Pillow (Image.resize) you can do: With skimage (skimage.transform.resize) you should get the same with:
You can lookup the documentation and the source code of the deprecated function. In short, using Pillow (Image.resize) you can do: With skimage (skimage.transform.resize) you should get the same with:
I had a similar problem using the Pystruct pystruct.learners.OneSlackSSVM. It occured because my training labels were floats, in stead of integers. In my case, it was because I initialized the labels with np.ones, without specifying dtype=np.int8. Hope it helps.
You could use a pass statement: Python 2.x documentation Python 3.x documentation However I doubt you want to do this, unless you just need to put something in as a placeholder until you come back and write the actual code for the if statement. If you have something like this: You can in general change it to this: But … Read more
To remove duplicates use set(a). To print duplicates, something like: Note that Counter is not particularly efficient (timings) and probably overkill here. set will perform better. This code computes a list of unique elements in the source order: or, more concisely: I don’t recommend the latter style, because it is not obvious what not seen.add(x) is doing (the set add() method always returns None, hence … Read more
The syntax for decorators with arguments is a bit different – the decorator with arguments should return a function that will take a function and return another function. So it should really return a normal decorator. A bit confusing, right? What I mean is: Here you can read more on the subject – it’s also possible to implement … Read more
Use numpy.array to use shape attribute. NOTE X.shape returns 3-items tuple for the given array; [n, T] = X.shape raises ValueError.
You can use df.loc[i], where the row with index i will be what you specify it to be in the dataframe.
The itertools module has a useful method called permutations(). The documentation says: itertools.permutations(iterable[, r]) Return successive r length permutations of elements in the iterable. If r is not specified or is None, then r defaults to the length of the iterable and all possible full-length permutations are generated. Permutations are emitted in lexicographic sort order. So, if … Read more
The function you’re after is numpy.linalg.norm. (I reckon it should be in base numpy as a property of an array — say x.norm() — but oh well). You can also feed in an optional ord for the nth order norm you want. Say you wanted the 1-norm: And so on.
You can use matplotlib for this. matplotlib has a mplot3d module that will do exactly what you want. The code above generates a figure like: