np-learn
np-learn copied to clipboard
Wrong example in Transposition
There is an example as following
# Row-major, C-order
# largest axis changes fastest
A = np.arange(2 * 3).reshape(2, 3).copy(order='C')
...
# GOTCHA: ravel will copy the array so that everything is contiguous
# if the order differs
print(id(A.base), id(A.ravel().base), id(A.ravel(order='F').base))
which outputs
140675174489296 140673647644144 140675174489296
But A.ravel() should share the underlayer c-array with A, not the A.ravel(order='F').
Then why id(A.base) and id(A.ravel(order='F').base) have the same value? The reason is that they both are the None object, because A and A.ravel(order='F') own their memory.
So the right example should be:
print(id(A), id(A.ravel().base), id(A.ravel(order='F')))
outputs like something as:
4945177616 4945177616 4945266368
BTW, thanks to this nice tutorial.
You're correct, thanks for pointing it out. I don't know why I had the extra .base arguments. Would you like to submit a PR? Edit. nvm, it's quick enough I can just do it now