Matplotlib plots: removing axis, legends and white spaces

I think that the command axis(‘off’) takes care of one of the problems more succinctly than changing each axis and the border separately. It still leaves the white space around the border however. Adding bbox_inches=’tight’ to the savefig command almost gets you there, you can see in the example below that the white space left is much smaller, but still present. … Read more

No Multiline Lambda in Python: Why not?

Look at the following: Is this a lambda returning (y, [1,2,3]) (thus map only gets one parameter, resulting in an error)? Or does it return y? Or is it a syntax error, because the comma on the new line is misplaced? How would Python know what you want? Within the parens, indentation doesn’t matter to python, so you … Read more

What are the differences between numpy arrays and matrices? Which one should I use?

Numpy matrices are strictly 2-dimensional, while numpy arrays (ndarrays) are N-dimensional. Matrix objects are a subclass of ndarray, so they inherit all the attributes and methods of ndarrays. The main advantage of numpy matrices is that they provide a convenient notation for matrix multiplication: if a and b are matrices, then a*b is their matrix product. On the other hand, as … Read more

How does str(list) work?

Well you have a total of 4 questions, let us go one by one. 1. Why does str(list) returns how we see list on the console? How does str(list) work? What is str() and __str__()? The str() callable is to return a printable form of the object only! From the docs str(object) does not always attempt to return a string that is acceptable to eval(); its goal is to return a … Read more