回答此问题可获得 20 贡献值,回答如果被采纳可获得 50 分。
<p>我是python和OOP概念的新手,我无法理解某些事情,比如为什么有些函数会更改原始对象,而有些则不会。为了更好地理解它,我在下面的代码片段中添加了注释。感谢任何帮助。谢谢。在</p>
<pre><code>from numpy import *
a = array([[1,2,3],[4,5,6]],float)
print a
array([[ 1., 2., 3.],
[ 4., 5., 6.]]) ### Result reflected after using print a
a.reshape(3,2)
array([[ 1., 2.],
[ 3., 4.],
[ 5., 6.]]) ### Result reflected on IDE after applying the reshape function
print a
array([[ 1., 2., 3.],
[ 4., 5., 6.]]) ### It remains the same as original value of "a", which is expected.
a.fill(0)
print a
[[ 0. 0. 0.]
[ 0. 0. 0.]] ### It changed the value of array "a" , why?
#############
type(reshape) ### If i try to find the type of "reshape" , i get an answer as "function" .
<type 'function'>
type(fill) ### I get a traceback when i try to find type of "fill", why?
Traceback (most recent call last):
File "<pyshell#12>", line 1, in <module>
type(fill)
NameError: name 'fill' is not defined
</code></pre>
<p><strong>我的问题是:</strong></p>
<p>我的函数是怎样改变的?在</p>
<p>2)考虑(如果我错了,请纠正我)如果“fill”是一个函数,那么为什么它会改变对象“a”的原始值?在</p>
<p>3)当我使用type(fill)时,为什么要进行回溯?在</p>