I mainly use numpy to perform data analysis without understanding the underlying program, so this may be obvious.
I do not understand the difference between setting an attribute, simply assigning it against a method call that modifies this attribute in place. An example where you can do this:
In [1]: import numpy as np In [2]: a = np.array([[1, 2, 3], ...: [4, 5, 6]]) In [3]: a.shape Out[3]: (2, 3) In [4]: a.reshape(3,2) Out[4]: array([[1, 2], [3, 4], [5, 6]]) In [5]: a Out[5]: array([[1, 2, 3], [4, 5, 6]]) In [6]: a.resize(3,2) In [7]: a Out[7]: array([[1, 2], [3, 4], [5, 6]]) In [8]: a.shape = (6,) In [9]: a Out[9]: array([1, 2, 3, 4, 5, 6]) In [10]: a.__setattr__('shape',(3,2)) In [11]: a Out[11]: array([[1, 2], [3, 4], [5, 6]])
I do not understand what is the difference between inputs 6 and 8 . It is clear that both modify the a.shape attribute in place, rather than returning the reconstructed object, as in 4 . Both of them only call a.__setattr__() , as in 10 ? If so, why do they both exist?
(I know that a.resize() has additional capacity to increase or decrease the allocated memory, but I do not use it here --- does this duality only using the method adds some other capacity?)