What is the difference between ndarray and array in NumPy?

numpy.array is just a convenience function to create an ndarray; it is not a class itself. You can also create an array using numpy.ndarray, but it is not the recommended way. From the docstring of numpy.ndarray: Arrays should be constructed using array, zeros or empty … The parameters given here refer to a low-level method … Read more

Deprecation status of the NumPy matrix class

tl; dr: the numpy.matrix class is getting deprecated. There are some high-profile libraries that depend on the class as a dependency (the largest one being scipy.sparse) which hinders proper short-term deprecation of the class, but users are strongly encouraged to use the ndarray class (usually created using the numpy.array convenience function) instead. With the introduction … Read more

How do I convert a PIL Image into a NumPy array?

You’re not saying how exactly putdata() is not behaving. I’m assuming you’re doing >>> pic.putdata(a) Traceback (most recent call last): File “…blablabla…/PIL/Image.py”, line 1185, in putdata self.im.putdata(data, scale, offset) SystemError: new style getargs format but argument is not a tuple This is because putdata expects a sequence of tuples and you’re giving it a numpy … Read more

Concatenating two one-dimensional NumPy arrays

The line should be: numpy.concatenate([a,b]) The arrays you want to concatenate need to be passed in as a sequence, not as separate arguments. From the NumPy documentation: numpy.concatenate((a1, a2, …), axis=0) Join a sequence of arrays together. It was trying to interpret your b as the axis parameter, which is why it complained it couldn’t … Read more