I suppose this is a bit of a beginner's question, but I'm wondering about the more pythonic approach to use when you're presented with a situation where you're using class methods from a class defined in a module, as well as methods defined within the module itself. I'll use numpy as an example.
import numpy as np
foo = np.matrix([[3, 4], [9, 12]])
# Get norm (without using linalg)
norm = np.sqrt(foo.dot(foo.T)).diagonal()
I can use a mixed case, like this, where I'm calling methods of foo and methods defined in numpy, or I can write the code as below:
norm = np.diagonal(np.sqrt(np.dot(foo, foo.T)))
I would prefer using foo.bar.baz.shoop.doop syntax, myself, but in this case I can't, as sqrt isn't a method of foo. So, what would be the more pythonic way to write a line like this?
Incidentally, as a side-question, are class methods usually more optimized, compared to methods defined in a module? I don't understand too well what's going on under the hood, but I assumed (again using numpy as an example) that numpy has an np.dot method that is written for the general case where arg can be an array or a matrix, while np.matrix.dot is reimplemented and optimized only for matrix operations. Please correct me if I'm wrong in this.