You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm in the process of reading the book for python machine learning (PML). And I followed the PML to learn more about numpy through the Appendix F of this book.
For section F.6, it covers fancy indexing will always return a copy of ndarray. But in section F.7 it shows you can do the assignment to fancy indexed array and the result will be written to the original array. I'm confused.
That's not consistent with fancy indexing should return a copy instead of a view of the array. If arr[mask] returns a copy, then the following assignment will assign results to the copy instead of the source.
After I did some research, I found the post here explains everything.
When you do c = a[b], a.__get_item__ is called with b as its only argument, and whatever gets returned is assigned to c.
When you doa[b] = c, a.__setitem__ is called with b and c as arguments and whatever gets returned is silently discarded.
I hope @rasbt can elaborately mention the python implementation difference of indexed array being used as rvalue and lvalue.
The text was updated successfully, but these errors were encountered:
I'm in the process of reading the book for python machine learning (PML). And I followed the PML to learn more about numpy through the Appendix F of this book.
For section F.6, it covers fancy indexing will always return a copy of ndarray. But in section F.7 it shows you can do the assignment to fancy indexed array and the result will be written to the original array. I'm confused.
That's not consistent with fancy indexing should return a copy instead of a view of the array. If
arr[mask]
returns a copy, then the following assignment will assign results to the copy instead of the source.After I did some research, I found the post here explains everything.
I hope @rasbt can elaborately mention the python implementation difference of indexed array being used as
rvalue
andlvalue
.The text was updated successfully, but these errors were encountered: