I don't understand this bit: "Numpy's notation has the advantage to make 
the most expensive operations harder to write, it also easily reminds us 
that arrays in numpy are row-major." How does this make the more expensive 
operation harder to write?

Just by writing this (for a a 2D array):
for i in a.T:
   do_something(i)
or even worse that:
for i in range(a.shape[1]):
   do_something(a[:,i])
I already know that I'm doing something slower than just:
for i in a:
    do_something(i)

In the first case, I'm transposing (actually, numpy does nothing but 
returning another view of the data, so the transpose itself is cheap). 
Since numpy does not actually copy the data elsewhere, iterating over a.T 
is expensive because you are doing it column-wise in a row-major layout. So 
numpy user might have the good impression for the wrong reason 
(transposing) but the result is the same.

In the second case, it's just not the Python's way of doing it.

In both cases, beginers are usually surprised that one axis is blessed. 
They complain and they are told that there is a perfectly good reason to do 
so. They learn and they adapt. That's what I'm doing there also for another 
language which is not python: I want to learn why it was done that way in 
Julia. :)


> To me (but I didn't design Julia so what do I know) have a[i] refer to a 
> specific element makes sense because it makes it easy to write a loop that 
> does something to each element without having to worry about the dimensions 
> of the array. 
>
> To me, having a[i] is redundant: almost all operators (inplace operators 
included) has a per element counterpart which makes the writing of explicit 
loops superfluous in most of the cases. 

Reply via email to