what is difference between np.copy and np.copy() ? I think np.copy() creates copy of numpy array object and np.copy is attribute of the object. But when i try
print(np.copy)
or print(someObject.copy())
it shows message
'<built-in method copy of numpy.ndarray object at 0x00000214E46468D0>'
or
<function copy at 0x00000214E2B3BD30>
I'm expecting some value or object. Can you explain to me what is happening here?
edit: What is difference between
SomeObject.copy()
and
SomeObject.copy
?
CodePudding user response:
Your print
just displays the function or method identity. It doesn't run/evaluate either.
If x
is an numpy
array, np.copy(x)
and x.copy()
do the same thing.
More generally np.copy(x)
will return an array regardless of what x
is, while x.copy()
uses the copy method defined for the x class
. Those may be different.
In [175]: x = np.array([1, 2, 3])
In [176]: np.copy(x)
Out[176]: array([1, 2, 3])
In [177]: x.copy()
Out[177]: array([1, 2, 3])
In [178]: y = [1, 2, 3]
In [179]: np.copy(y)
Out[179]: array([1, 2, 3])
In [180]: y.copy()
Out[180]: [1, 2, 3]
CodePudding user response:
They are two different things. print(np.copy)
copies numpy. print(someObject.copy)
copies the object. Please upvote this answer to support me