+ 1 to Gabriel's reply.

On Tuesday, April 5, 2016 at 2:36:09 PM UTC+1, Gabriel Gellner wrote:
>
> you can do the python example as:
>
> a[[1, 4] + range(7, 17, 2)]
> (ignoring the issues that this is not the same range as julia since python 
> uses 0-based indices ...)
>
> you don't need to index with an ndarray, and that way you can get the nice 
> use of the + operator for concatenate.
>
> Lacking the : for range does make some code more verbose, but you get used 
> to it.
>
> For the julia example isn't matlab like concatenation using ';' being 
> removed from julia?
>
> As to the overall topic I don't think it is fair to have to poo-poo python 
> to also feel that julia does it well. I really like both. Arguing about 0 
> vs 1 based indexing is like emacs vs vi ... it leads to nothing but madness 
> ...
>
> R + matlab + julia + fortran + Mathematica use 1 based and the world 
> hasn't ended
>
> sometimes 0 based is nice, but you get used to not having it, just like 
> you get used to having it.
>
> As for the truncating integer div ... I do hate that that in python and do 
> "from __future__ import division" always ;)
>
> On Monday, April 4, 2016 at 11:55:40 PM UTC-7, DNF wrote:
>>
>> Typo, I meant to type:
>>
>> Python 3.5
>> a[i*len(a)//n:(i+1)*len(a)//n]
>>
>> Julia:
>> a[1+i*end÷n:(i+1)end÷n]
>>
>> I'm just learning Python, and must say I find indexing in Python to be 
>> very awkward compared to Julia or Matlab. Do you have any suggestion for 
>> how I should do this in Python?
>> a[[1; 4; 7:2:15]]
>> So far I've got:
>> a[np.concatenate(([1,4], np.arange(7,17,2)))]
>>
>>
>>
>>
>> On Tuesday, April 5, 2016 at 8:46:57 AM UTC+2, DNF wrote:
>>>
>>>
>>> On Saturday, April 2, 2016 at 1:55:55 PM UTC+2, Spiritus Pap wrote:
>>>>
>>>> A simple example why it makes my *life hard*: Assume there is an array 
>>>> of size 100, and i want to take the i_th portion of it out of n. This is a 
>>>> common scenario for research-code, at least for me and my friends.
>>>> In python:
>>>> a[i*100/n:(i+1)*100/n]
>>>> In julia:
>>>> a[1+div(i*100,n):div((i+1)*100,n)]
>>>>
>>>> A lot more cumbersome in julia, and it is annoying and unattractive. 
>>>> This is just a simple example.
>>>>
>>>
>>> Python 3.5
>>> a[i*len(a)//n:(i+1)*len(a)//n]
>>>
>>> Julia:
>>> a[1+i*end÷5:(i+1)end÷5] 
>>>
>>>

Reply via email to