I went to look up the source to np.transpose ( source ) and the definition seems circular?
def transpose(a, axes=None):
try:
transpose = a.transpose
except AttributeError:
return _wrapit(a, 'transpose', axes)
return transpose(axes)
If all transpose(a) does is call a.transpose then how do we look up a.transpose?
What part of the code is doing the transposition? All I see is referral to another transpose function.
It's not actually a circular reference.
a.transposeis a reference to the object's method, not the function defined by numpy. It's effectively saying "If objectaalready has atransposemethod, then leave it alone; otherwise, use_wrapitto wrap the objectain anndarrayobject".As the
ndarrayclass has atransposemethod, forcing the Python object into that class gives the object access to the method.This is a little outside my area of expertise, but it would appear that
ndarrayis defined in the C portion of the numpy code, so that would be where you'd find the actual logic behind it.