3 ms·
Numpy array syntax inconsistent to the degree it can be considered broken. For instance, to take elements number 4,3,2 of an array in Python, one writes A[3:0:-
by Mikhail_K 6y ago
Numpy array syntax inconsistent to the degree it can be considered broken. For instance, to take elements number 4,3,2 of an array in Python, one writes A[3:0:-1], but for the elements 3,2,1 one has to write A[2::-1], because someone decided that making A[-1] refer to the last element of an array is "intuitive", and so A[2:-1:-1] will return empty slice.
Now if you want to use array comprehensions, the first case looks similar: [A[k] for k in range(3,0,-1)] but the second now has to be [A[k] for k in range(2,-1,-1)].
Further, for some reason, array and matrix are different types and one has to convert back and forth between them.
- joaogui1 6y agoYou don't need the matrix type in Numpy, it's just syntax sugar over a 2-dimensional array
- tgb 6y agoThe matrix class is now officially deprecated, FYI, so just use array everywhere. I guess the generic way to write that would be A[bottom:top+1][::-1]. But the blame there goes to Python, not numpy, since the same is true of lists.