Re: [julia-users] Re: type specification syntax for array

2015-04-22 Thread Wai Yip Tung
nt32, Int32)[] In nightly it is Tuple{Int32, Int32}[] On Tuesday, April 21, 2015 at 7:12:01 PM UTC+2, Wai Yip Tung wrote: Wai Yip Tung <mailto:w...@tungwaiyip.info> Tuesday, April 21, 2015 10:12 AM I have a newbie question. I have programming background in Python, Java, C. In some cases

[julia-users] type specification syntax for array

2015-04-21 Thread Wai Yip Tung
I have a newbie question. I have programming background in Python, Java, C. In some cases in Julia, like an empty array, I need to explicitly specify the type. I am rather confused about the syntax. There a a few plausible options like parenthesis, braces, colon. I have trouble to pick the right

Re: [julia-users] Define `similar` function for a custom array

2015-02-05 Thread Wai Yip Tung
[428]: sort(s) access to undefined reference while loading In[428], in expression starting on line 1 in sort at sort.jl:342 Wai yip On Thursday, February 5, 2015 at 3:47:26 AM UTC-8, Milan Bouchet-Valat wrote: > > Le mercredi 04 février 2015 à 23:11 -0800, Wai Yip Tung a écrit :

[julia-users] Define `similar` function for a custom array

2015-02-04 Thread Wai Yip Tung
I have successfully defined a custom array Ngram. type Ngram <: AbstractArray{ASCIIString,1} seq::ASCIIString n::Int end function getindex(s::Ngram, i::Int) s.seq[i:i+s.n-1] end function Base.size(s::Ngram) length(s.seq) - s.n + 1 end It works as I expected. For example In [21

Re: [julia-users] Re: short circuit list comprehension

2015-02-03 Thread Wai Yip Tung
rewrites the list comprehension as a loop and inserts a break statement On Friday, January 30, 2015 at 12:51:13 AM UTC-6, Wai Yip Tung wrote: Wai Yip Tung <mailto:w...@tungwaiyip.info> Thursday, January 29, 2015 10:51 PM I want to apply function f() over a range of value. f() returns true

[julia-users] short circuit list comprehension

2015-01-29 Thread Wai Yip Tung
I want to apply function f() over a range of value. f() returns true for success and false for failure. Since f() is expensive, I want short circuit computation, i.e. it stops after the first failure. In python, I can do this in an elegant way with the all() function and generator expression.

Re: [julia-users] Re: Question about list of list; equivalent to Python's key paramater?

2015-01-26 Thread Wai Yip Tung
(y)) ) > 2-element Array{Array{Int64,1},1}: > [1,2,3] > [1,2] > > Note, Josh's trick is used to avoid concatenation. > > > On Mon, 2015-01-26 at 18:16, Joshua Adelman > wrote: > > On Monday, January 26, 2015 at 12:09:40 PM UTC-5, Joshua Adelman wrote:

[julia-users] Question about list of list; equivalent to Python's key paramater?

2015-01-26 Thread Wai Yip Tung
I'm trying to construct a list of list and do some operation on it. In Python I would do In [7]: ll = [[1,2],[1,2,3],[7]] Say I want to sort them by the length of the list, many function accepts a `key` parameter. In this case I want the `key` to be `len`. In [8]: max(ll, key=len) Out[8]: [1,

Re: [julia-users] random sample given a probability

2014-02-20 Thread Wai Yip Tung
efan Karpinski wrote: > > On Thu, Feb 20, 2014 at 1:36 AM, Wai Yip Tung > > > wrote: > >> I am trying to port some code from Python to Julia. I was using a >> function numpy.random.choice, which accept a parameter to define >> probability of each individual entry.

[julia-users] random sample given a probability

2014-02-20 Thread Wai Yip Tung
I am trying to port some code from Python to Julia. I was using a function numpy.random.choice, which accept a parameter to define probability of each individual entry. I wonder if there is a corresponding Julia function. Another more basic question is how do we do number formatting like %0.2f ?