Then I remember sth else. Most probably I have tried ones(size(a)) in Julia 
when `a` is a real number, and it does not do what the same command does in 
Matlab.
There are some other indexing that work in Julia, e.g.,
a=1.0
a[1]
a[1,1]
a[1,1,1,1]
a[end,end,end]
all return 1.0. But if I say size(a) it returns (). 
Or if I say b=ones(1,1,1)
then again b[1,1,1,1,1] or b[1,1,:,1] return 1.0, but b[1,1,1,:] throws an 
error.

On Monday, November 30, 2015 at 10:47:39 PM UTC+1, Mauro wrote:
>
> Your welcome.  Your recollection is wrong though, this was possible in 
> 0.2 and 0.3; I just checked (I don't have a 0.1 build but maybe I 
> should...). 
>
> On Mon, 2015-11-30 at 22:25, Ehsan Eftekhari <[email protected] 
> <javascript:>> wrote: 
> > Thanks Mauro. As you predicted, my question was about the reasoning 
> behind 
> > this behavior. If I remember correctly, it was not possible to use 
> getindex 
> > on real numbers in Julia 0.3. I was not sure why it is added to 0.4. 
> > 
> > On Monday, November 30, 2015 at 10:01:54 AM UTC+1, Mauro wrote: 
> >> 
> >> As it says, there is no method for it.  You could add it yourself: 
> >> 
> >> Base.getindex(f::Float64, ::Colon) = f # or whatever you like 
> >> 
> >> However, the philosophical question is: should you be allowed to index 
> >> into a float (or int)?  Julia usually puts convenience before 
> strictness 
> >> and allows this.  I'm not sure there are technical reasons to draw the 
> >> line at `1[:]`.  If no-one gives one, you could open a pull request 
> >> (probably should add a method for `q[1:end]` too). 
> >> 
> >> On Mon, 2015-11-30 at 09:32, Ehsan Eftekhari <[email protected] 
> >> <javascript:>> wrote: 
> >> >  I have a question about this behaviour of getindex in Julia: 
> >> > 
> >> > if I say 
> >> > 
> >> > julia> a=1.0 
> >> > 1.0 
> >> > 
> >> > then 
> >> > 
> >> > julia> a[1] 
> >> > 1.0 
> >> > 
> >> > julia> a[end] 
> >> > 1.0 
> >> > 
> >> > but 
> >> > 
> >> > julia> a[:] 
> >> > ERROR: MethodError: `getindex` has no method matching 
> >> getindex(::Float64, 
> >> > ::Colon) 
> >> > Closest candidates are: 
> >> >   getindex(::Number) 
> >> >   getindex(::Number, ::Integer) 
> >> >   getindex(::Number, ::Integer...) 
> >> >   ... 
> >> > 
> >> > Why the last one does not work? 
> >> 
>

Reply via email to